Spaces:
Sleeping
Sleeping
File size: 1,354 Bytes
db9a907 |
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 |
import gradio as gr
from transformers import pipeline
# Load the sentiment analysis pipeline
sentiment_analyzer = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")
def analyze_sentiment(text):
if not text.strip():
return "قم بإدخال النص للتحليل."
result = sentiment_analyzer(text)[0]
return f"التقييم المتوقع: {result['label']} نجمة "
# Define the Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# تحليل المشاعر باستخدام BERT")
with gr.Row():
input_text = gr.Textbox(label="أدخل النص", placeholder="اكتب جملة أو فقرة...")
analyze_button = gr.Button("تحليل المشاعر")
output_text = gr.Textbox(label="نتيجة التحليل", interactive=False)
examples = [
"أنا أحب هذا المنتج! إنه رائع!",
"هذه كانت أسوأ تجربة مررت بها على الإطلاق.",
"الفيلم كان عاديًا، ليس رائعًا ولكن ليس سيئًا أيضًا.",
"رائع جدًا! أنصح الجميع به."
]
gr.Examples(examples, inputs=input_text)
analyze_button.click(analyze_sentiment, inputs=input_text, outputs=output_text)
# Launch the app
demo.launch() |