Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
deployed_repo_id = "maryaa4/my-arabic-sentiment-model"
|
| 5 |
+
loaded_sentiment_pipeline = pipeline('sentiment-analysis', model=deployed_repo_id, trust_remote_code=True)
|
| 6 |
+
|
| 7 |
+
def predict_sentiment(text):
|
| 8 |
+
if not text:
|
| 9 |
+
return "Please enter some text for sentiment analysis."
|
| 10 |
+
result = loaded_sentiment_pipeline(text)
|
| 11 |
+
label = result[0]['label']
|
| 12 |
+
score = result[0]['score']
|
| 13 |
+
return f"Sentiment: {label.capitalize()}, Confidence: {score:.4f}"
|
| 14 |
+
|
| 15 |
+
iface = gr.Interface(
|
| 16 |
+
fn=predict_sentiment,
|
| 17 |
+
inputs=gr.Textbox(lines=5, placeholder="أدخل النص العربي هنا..."),
|
| 18 |
+
outputs="text",
|
| 19 |
+
title="Arabic Sentiment Analysis",
|
| 20 |
+
description=f"A sentiment analysis model for Arabic text, deployed from maryaa4/my-arabic-sentiment-model. Enter Arabic text and get the predicted sentiment."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
iface.launch(share=True) # share=True for a temporary public link
|