File size: 1,172 Bytes
047764b
 
 
 
 
bf4d290
047764b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

# Load the fine-tuned model and tokenizer into a pipeline
#model_path = "model"  # Replace with your actual model path
sentiment_pipeline = pipeline("sentiment-analysis", model="Walid-Ahmed/arabic-sentiment-model")


# Define label mapping
label_map = {
    "LABEL_0": "Negative",
    "LABEL_1": "Positive"
}

# Define a function to process the input and return the sentiment analysis result
def analyze_sentiment(text):
    result = sentiment_pipeline(text)
    # Extract the label and confidence score from the result
    label = result[0]['label']
    score = result[0]['score']
    return f"Sentiment: {label}, Confidence: {score:.2f}"

# Create a Gradio interface
interface = gr.Interface(
    fn=analyze_sentiment,  # Function to process input
    inputs="text",         # Text input field
    outputs="text",        # Text output field
    title="Arabic Sentiment Analysis",
    description="Enter an Arabic sentence and get the sentiment (positive or negative).",
    examples=[["هذا المنتج رائع جدا"], ["هذا المنتج سيء للغاية"]]
)

# Launch the Gradio app
interface.launch()