Almahfouz commited on
Commit
a674444
1 Parent(s): 6765e62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -1,6 +1,8 @@
1
- import gradio as gr # استدعاء المكتبات المطلوبه
2
  from transformers import pipeline
3
  from gtts import gTTS
 
 
4
 
5
  # 1. إعداد نموذج تلخيص النصوص باللغة الإنجليزية
6
  summarization_pipeline_en = pipeline("summarization", model="facebook/bart-large-cnn")
@@ -16,7 +18,8 @@ def summarize_text_en(text):
16
  # 4. تحويل النص إلى صوت باستخدام gTTS
17
  def text_to_speech(text, lang_code):
18
  tts = gTTS(text=text, lang=lang_code)
19
- audio_path = f"summary_audio_{lang_code}.mp3"
 
20
  tts.save(audio_path)
21
  return audio_path
22
 
@@ -102,5 +105,4 @@ with gr.Blocks() as iface:
102
  outputs=[transcribed_text]
103
  )
104
 
105
- # 9. تشغيل الواجهة
106
- iface.launch()
 
1
+ import gradio as gr
2
  from transformers import pipeline
3
  from gtts import gTTS
4
+ import os
5
+ from tempfile import gettempdir
6
 
7
  # 1. إعداد نموذج تلخيص النصوص باللغة الإنجليزية
8
  summarization_pipeline_en = pipeline("summarization", model="facebook/bart-large-cnn")
 
18
  # 4. تحويل النص إلى صوت باستخدام gTTS
19
  def text_to_speech(text, lang_code):
20
  tts = gTTS(text=text, lang=lang_code)
21
+ temp_dir = gettempdir()
22
+ audio_path = os.path.join(temp_dir, f"summary_audio_{lang_code}.mp3")
23
  tts.save(audio_path)
24
  return audio_path
25
 
 
105
  outputs=[transcribed_text]
106
  )
107
 
108
+ # Gradio will automatically launch this in Hugging Face Spaces, so no need for iface.launch()