Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the fine-tuned model and tokenizer into a pipeline
|
5 |
+
#model_path = "model" # Replace with your actual model path
|
6 |
+
sentiment_pipeline = pipeline("sentiment-analysis", model="Walid-Ahmed/arabic-sentiment-model", tokenizer=model_path)
|
7 |
+
|
8 |
+
|
9 |
+
# Define label mapping
|
10 |
+
label_map = {
|
11 |
+
"LABEL_0": "Negative",
|
12 |
+
"LABEL_1": "Positive"
|
13 |
+
}
|
14 |
+
|
15 |
+
# Define a function to process the input and return the sentiment analysis result
|
16 |
+
def analyze_sentiment(text):
|
17 |
+
result = sentiment_pipeline(text)
|
18 |
+
# Extract the label and confidence score from the result
|
19 |
+
label = result[0]['label']
|
20 |
+
score = result[0]['score']
|
21 |
+
return f"Sentiment: {label}, Confidence: {score:.2f}"
|
22 |
+
|
23 |
+
# Create a Gradio interface
|
24 |
+
interface = gr.Interface(
|
25 |
+
fn=analyze_sentiment, # Function to process input
|
26 |
+
inputs="text", # Text input field
|
27 |
+
outputs="text", # Text output field
|
28 |
+
title="Arabic Sentiment Analysis",
|
29 |
+
description="Enter an Arabic sentence and get the sentiment (positive or negative).",
|
30 |
+
examples=[["هذا المنتج رائع جدا"], ["هذا المنتج سيء للغاية"]]
|
31 |
+
)
|
32 |
+
|
33 |
+
# Launch the Gradio app
|
34 |
+
interface.launch()
|