File size: 992 Bytes
c00d063 4caa20a c00d063 5abbbb4 c00d063 5abbbb4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import gradio as gr
from transformers import pipeline
# تحميل النموذج
model = pipeline("text-classification",
model="CAMeL-Lab/bert-base-arabic-camelbert-da-sentiment")
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
data: list
@app.post("/predict")
def predict(item: Item):
text = item.data[0]
# استدعاء دالة التحليل الموجودة عندك
result = analyze(text)
return {"data": [result]}
def analyze(text):
if not text.strip():
return "الرجاء إدخال نص للتحليل"
result = model(text)[0]
return f"المشاعر: {result['label']}, الثقة: {result['score']:.2%}"
# أنشئ الواجهة وشغلها مباشرة
gr.Interface(
fn=analyze,
inputs=gr.Textbox(label="أدخل النص العربي"),
outputs=gr.Textbox(label="النتيجة"),
title="محلل المشاعر العربي"
).launch() |