SharifahMal commited on
Commit
db9a907
·
verified ·
1 Parent(s): 8823696

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the sentiment analysis pipeline
5
+ sentiment_analyzer = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")
6
+
7
+ def analyze_sentiment(text):
8
+ if not text.strip():
9
+ return "قم بإدخال النص للتحليل."
10
+ result = sentiment_analyzer(text)[0]
11
+ return f"التقييم المتوقع: {result['label']} نجمة "
12
+
13
+ # Define the Gradio interface
14
+ with gr.Blocks() as demo:
15
+ gr.Markdown("# تحليل المشاعر باستخدام BERT")
16
+
17
+ with gr.Row():
18
+ input_text = gr.Textbox(label="أدخل النص", placeholder="اكتب جملة أو فقرة...")
19
+
20
+ analyze_button = gr.Button("تحليل المشاعر")
21
+
22
+ output_text = gr.Textbox(label="نتيجة التحليل", interactive=False)
23
+
24
+ examples = [
25
+ "أنا أحب هذا المنتج! إنه رائع!",
26
+ "هذه كانت أسوأ تجربة مررت بها على الإطلاق.",
27
+ "الفيلم كان عاديًا، ليس رائعًا ولكن ليس سيئًا أيضًا.",
28
+ "رائع جدًا! أنصح الجميع به."
29
+ ]
30
+
31
+ gr.Examples(examples, inputs=input_text)
32
+
33
+ analyze_button.click(analyze_sentiment, inputs=input_text, outputs=output_text)
34
+
35
+ # Launch the app
36
+ demo.launch()