Walid-Ahmed's picture
Update app.py
bf4d290 verified
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()