Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
model_name = "HooshvareLab/bert-fa-base-uncased-sentiment-digikala"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
sentiment_analyzer = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
| 11 |
+
|
| 12 |
+
def analyze_sentiment(text):
|
| 13 |
+
result = sentiment_analyzer(text)[0]
|
| 14 |
+
label = result['label']
|
| 15 |
+
score = round(result['score'], 3)
|
| 16 |
+
return f"نتیجه: {label} ({score})"
|
| 17 |
+
|
| 18 |
+
iface = gr.Interface(
|
| 19 |
+
fn=analyze_sentiment,
|
| 20 |
+
inputs=gr.Textbox(lines=2, placeholder="متن خود را وارد کنید..."),
|
| 21 |
+
outputs="text",
|
| 22 |
+
title="تحلیل احساسات متون فارسی",
|
| 23 |
+
description="مدلی برای تشخیص مثبت، منفی یا خنثی بودن متن فارسی."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
iface.launch()
|