Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
import torch
|
4 |
|
5 |
# Load sentiment analysis models
|
6 |
english_sentiment_model = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")
|
7 |
-
arabic_sentiment_model = pipeline("text-classification", model="CAMeL-Lab/bert-base-arabic-camelbert-da-sentiment")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
def analyze_sentiment(text, language):
|
10 |
if language == "English":
|
11 |
result = english_sentiment_model(text)
|
|
|
12 |
else:
|
13 |
result = arabic_sentiment_model(text)
|
14 |
-
|
|
|
|
|
15 |
|
16 |
# Create Gradio interface
|
17 |
iface = gr.Interface(
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
# Load sentiment analysis models
|
5 |
english_sentiment_model = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")
|
6 |
+
arabic_sentiment_model = pipeline("text-classification", model="CAMeL-Lab/bert-base-arabic-camelbert-da-sentiment")
|
7 |
+
|
8 |
+
# Define label meanings for Arabic sentiment analysis
|
9 |
+
arabic_labels = {
|
10 |
+
"positive": "إيجابي",
|
11 |
+
"negative": "سلبي",
|
12 |
+
"neutral": "محايد" # Add any other labels that your model may use
|
13 |
+
}
|
14 |
|
15 |
def analyze_sentiment(text, language):
|
16 |
if language == "English":
|
17 |
result = english_sentiment_model(text)
|
18 |
+
return result[0]['label'], result[0]['score']
|
19 |
else:
|
20 |
result = arabic_sentiment_model(text)
|
21 |
+
label = result[0]['label']
|
22 |
+
arabic_label = arabic_labels.get(label, "غير معروف") # Default to "Unknown" if label not found
|
23 |
+
return arabic_label, result[0]['score']
|
24 |
|
25 |
# Create Gradio interface
|
26 |
iface = gr.Interface(
|