File size: 990 Bytes
2e810d8
50b5fb0
 
078b91e
50b5fb0
 
 
d2104f8
50b5fb0
 
 
d2104f8
50b5fb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline
import torch 

# Load sentiment analysis models
english_sentiment_model = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")
arabic_sentiment_model = pipeline("sentiment-analysis", model="akhooli/arabic-sentiment")

def analyze_sentiment(text, language):
    if language == "English":
        result = english_sentiment_model(text)
    else:
        result = arabic_sentiment_model(text)
    return result[0]['label'], result[0]['score']

# Create Gradio interface
iface = gr.Interface(
    fn=analyze_sentiment,
    inputs=[
        gr.inputs.Textbox(label="Enter text"),
        gr.inputs.Radio(choices=["English", "Arabic"], label="Select Language")
    ],
    outputs=[
        gr.outputs.Label(label="Sentiment"),
        gr.outputs.Number(label="Confidence Score")
    ],
    title="Sentiment Analysis",
    description="Analyze the sentiment of text in English and Arabic."
)

iface.launch()