Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,9 +10,9 @@ from transformers import pipeline
|
|
| 10 |
|
| 11 |
deployed_repo_id = "maryaa4/my-arabic-sentiment-model"
|
| 12 |
loaded_sentiment_pipeline = pipeline(
|
| 13 |
-
|
| 14 |
model=deployed_repo_id,
|
| 15 |
-
trust_remote_code=True
|
| 16 |
)
|
| 17 |
|
| 18 |
def predict_sentiment(text: str) -> str:
|
|
@@ -20,8 +20,8 @@ def predict_sentiment(text: str) -> str:
|
|
| 20 |
return "رجاءً أدخل نص عربي عشان أقدر أحلله 📝"
|
| 21 |
|
| 22 |
result = loaded_sentiment_pipeline(text)
|
| 23 |
-
label = result[0][
|
| 24 |
-
score = result[0][
|
| 25 |
|
| 26 |
# تقدرين تغيرين طريقة العرض هنا
|
| 27 |
return f"التصنيف: {label}\nنسبة الثقة: {score:.2f}"
|
|
@@ -35,7 +35,7 @@ iface = gr.Interface(
|
|
| 35 |
inputs=gr.Textbox(lines=5, placeholder="أدخل النص العربي هنا..."),
|
| 36 |
outputs="text",
|
| 37 |
title="Arabic Sentiment Analysis",
|
| 38 |
-
description="موديل لتحليل المشاعر في النصوص العربية باستخدام النموذج: maryaa4/my-arabic-sentiment-model"
|
| 39 |
)
|
| 40 |
|
| 41 |
# ======================
|
|
@@ -46,7 +46,11 @@ app = FastAPI()
|
|
| 46 |
|
| 47 |
# نحط التوكن في Secrets في السبيس باسم TELEGRAM_TOKEN
|
| 48 |
BOT_TOKEN = os.getenv("TELEGRAM_TOKEN")
|
| 49 |
-
TELEGRAM_API =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
@app.post("/telegram")
|
| 52 |
async def telegram_webhook(request: Request):
|
|
@@ -65,10 +69,13 @@ async def telegram_webhook(request: Request):
|
|
| 65 |
|
| 66 |
if TELEGRAM_API:
|
| 67 |
try:
|
| 68 |
-
requests.post(
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
| 72 |
except Exception as e:
|
| 73 |
print("Error sending message to Telegram:", e)
|
| 74 |
|
|
|
|
| 10 |
|
| 11 |
deployed_repo_id = "maryaa4/my-arabic-sentiment-model"
|
| 12 |
loaded_sentiment_pipeline = pipeline(
|
| 13 |
+
"sentiment-analysis",
|
| 14 |
model=deployed_repo_id,
|
| 15 |
+
trust_remote_code=True,
|
| 16 |
)
|
| 17 |
|
| 18 |
def predict_sentiment(text: str) -> str:
|
|
|
|
| 20 |
return "رجاءً أدخل نص عربي عشان أقدر أحلله 📝"
|
| 21 |
|
| 22 |
result = loaded_sentiment_pipeline(text)
|
| 23 |
+
label = result[0]["label"]
|
| 24 |
+
score = result[0]["score"]
|
| 25 |
|
| 26 |
# تقدرين تغيرين طريقة العرض هنا
|
| 27 |
return f"التصنيف: {label}\nنسبة الثقة: {score:.2f}"
|
|
|
|
| 35 |
inputs=gr.Textbox(lines=5, placeholder="أدخل النص العربي هنا..."),
|
| 36 |
outputs="text",
|
| 37 |
title="Arabic Sentiment Analysis",
|
| 38 |
+
description="موديل لتحليل المشاعر في النصوص العربية باستخدام النموذج: maryaa4/my-arabic-sentiment-model",
|
| 39 |
)
|
| 40 |
|
| 41 |
# ======================
|
|
|
|
| 46 |
|
| 47 |
# نحط التوكن في Secrets في السبيس باسم TELEGRAM_TOKEN
|
| 48 |
BOT_TOKEN = os.getenv("TELEGRAM_TOKEN")
|
| 49 |
+
TELEGRAM_API = (
|
| 50 |
+
f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage"
|
| 51 |
+
if BOT_TOKEN
|
| 52 |
+
else None
|
| 53 |
+
)
|
| 54 |
|
| 55 |
@app.post("/telegram")
|
| 56 |
async def telegram_webhook(request: Request):
|
|
|
|
| 69 |
|
| 70 |
if TELEGRAM_API:
|
| 71 |
try:
|
| 72 |
+
requests.post(
|
| 73 |
+
TELEGRAM_API,
|
| 74 |
+
json={
|
| 75 |
+
"chat_id": chat_id,
|
| 76 |
+
"text": reply,
|
| 77 |
+
},
|
| 78 |
+
)
|
| 79 |
except Exception as e:
|
| 80 |
print("Error sending message to Telegram:", e)
|
| 81 |
|