Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
import joblib
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import hf_hub_download
|
|
|
|
| 4 |
|
| 5 |
-
# تحميل الملفات من مستودعك على Hugging Face
|
| 6 |
repo_id = "zico2m/comments-classifiers"
|
| 7 |
|
| 8 |
vectorizer_path = hf_hub_download(repo_id=repo_id, filename="tfidf_vectorizer.pkl")
|
|
@@ -14,7 +15,8 @@ vectorizer = joblib.load(vectorizer_path)
|
|
| 14 |
model = joblib.load(model_path)
|
| 15 |
sentiment_model = joblib.load(sentiment_path)
|
| 16 |
|
| 17 |
-
# دال
|
|
|
|
| 18 |
def classify_comment(text):
|
| 19 |
if not text.strip():
|
| 20 |
return "الرجاء إدخال نص صالح للتحليل."
|
|
@@ -22,7 +24,7 @@ def classify_comment(text):
|
|
| 22 |
# تحويل النص باستخدام TF-IDF
|
| 23 |
transformed_text = vectorizer.transform([text])
|
| 24 |
|
| 25 |
-
# التنبؤ
|
| 26 |
prediction = model.predict(transformed_text)[0]
|
| 27 |
sentiment = sentiment_model.predict(transformed_text)[0]
|
| 28 |
|
|
|
|
| 1 |
import joblib
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
+
import spaces
|
| 5 |
|
| 6 |
+
# تحميل الملفات من مستودعك على Hugging Face
|
| 7 |
repo_id = "zico2m/comments-classifiers"
|
| 8 |
|
| 9 |
vectorizer_path = hf_hub_download(repo_id=repo_id, filename="tfidf_vectorizer.pkl")
|
|
|
|
| 15 |
model = joblib.load(model_path)
|
| 16 |
sentiment_model = joblib.load(sentiment_path)
|
| 17 |
|
| 18 |
+
# استخدام @spaces.GPU حتى لو كان النموذج يعمل على الـ CPU، لترضى المنصة بالتشغيل
|
| 19 |
+
@spaces.GPU
|
| 20 |
def classify_comment(text):
|
| 21 |
if not text.strip():
|
| 22 |
return "الرجاء إدخال نص صالح للتحليل."
|
|
|
|
| 24 |
# تحويل النص باستخدام TF-IDF
|
| 25 |
transformed_text = vectorizer.transform([text])
|
| 26 |
|
| 27 |
+
# التنبؤ
|
| 28 |
prediction = model.predict(transformed_text)[0]
|
| 29 |
sentiment = sentiment_model.predict(transformed_text)[0]
|
| 30 |
|