assignment3 / app.py
SharifahMal's picture
Create app.py
db9a907 verified
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()