rakmik commited on
Commit
01408fd
·
verified ·
1 Parent(s): 1014a3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -1,14 +1,14 @@
1
  import urllib.parse
2
  import requests
3
  import gradio as gr
4
- from transformers import pipeline, MBartTokenizer
5
 
6
  # 🟢 API Templates للحصول على بيانات ويكيبيديا
7
  SEARCH_TEMPLATE = "https://ar.wikipedia.org/w/api.php?action=opensearch&search=%s&limit=1&namespace=0&format=json"
8
  CONTENT_TEMPLATE = "https://ar.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=%s"
9
 
10
- # 🔥 استخدام tokenizer بدون fast mode لتجنب المشاكل
11
- tokenizer = MBartTokenizer.from_pretrained("facebook/mbart-large-50", use_fast=False)
12
  summarizer = pipeline("summarization", model="facebook/mbart-large-50", tokenizer=tokenizer)
13
 
14
  def search_wikipedia(query):
@@ -35,6 +35,10 @@ def search_wikipedia(query):
35
  if not content:
36
  return "❌ المقالة لا تحتوي على معلومات كافية.", ""
37
 
 
 
 
 
38
  # 🟢 تحسين التلخيص بناءً على طول المقالة
39
  max_length = 200 if len(content) > 1000 else 100
40
  min_length = 50 if len(content) > 500 else 30
@@ -60,7 +64,7 @@ with gr.Blocks() as demo:
60
 
61
  chatbot = gr.Chatbot()
62
  msg = gr.Textbox(label="🔍 اكتب سؤالك هنا:")
63
- clear = gr.Button("🧹 مسح المحادثة")
64
 
65
  msg.submit(chatbot_response, [msg, chatbot], chatbot).then(
66
  lambda _: "", None, [msg], queue=False # 🟢 تصحيح التحديث التلقائي لحقل الإدخال
@@ -68,5 +72,4 @@ with gr.Blocks() as demo:
68
  clear.click(lambda: [], None, chatbot, queue=False)
69
 
70
  if __name__ == "__main__":
71
- demo.launch()
72
-
 
1
  import urllib.parse
2
  import requests
3
  import gradio as gr
4
+ from transformers import pipeline, MBart50Tokenizer
5
 
6
  # 🟢 API Templates للحصول على بيانات ويكيبيديا
7
  SEARCH_TEMPLATE = "https://ar.wikipedia.org/w/api.php?action=opensearch&search=%s&limit=1&namespace=0&format=json"
8
  CONTENT_TEMPLATE = "https://ar.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=%s"
9
 
10
+ # 🔥 استخدام tokenizer الصحيح
11
+ tokenizer = MBart50Tokenizer.from_pretrained("facebook/mbart-large-50", use_fast=False)
12
  summarizer = pipeline("summarization", model="facebook/mbart-large-50", tokenizer=tokenizer)
13
 
14
  def search_wikipedia(query):
 
35
  if not content:
36
  return "❌ المقالة لا تحتوي على معلومات كافية.", ""
37
 
38
+ # 🟢 ضبط طول الإدخال للتوافق مع حدود النموذج
39
+ max_input_length = 1024
40
+ content = content[:max_input_length]
41
+
42
  # 🟢 تحسين التلخيص بناءً على طول المقالة
43
  max_length = 200 if len(content) > 1000 else 100
44
  min_length = 50 if len(content) > 500 else 30
 
64
 
65
  chatbot = gr.Chatbot()
66
  msg = gr.Textbox(label="🔍 اكتب سؤالك هنا:")
67
+ clear = gr.Button("🧩 مسح المحادثة")
68
 
69
  msg.submit(chatbot_response, [msg, chatbot], chatbot).then(
70
  lambda _: "", None, [msg], queue=False # 🟢 تصحيح التحديث التلقائي لحقل الإدخال
 
72
  clear.click(lambda: [], None, chatbot, queue=False)
73
 
74
  if __name__ == "__main__":
75
+ demo.launch(share=True) # 🟢 تمكين المشاركة العامة