zico2m commited on
Commit
630fbae
·
verified ·
1 Parent(s): 729d9f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
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