mohamedlabed commited on
Commit
954db36
·
verified ·
1 Parent(s): e9a1460

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +41 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import whisper
4
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
5
+
6
+ # تحميل النماذج
7
+ model_whisper = whisper.load_model("base")
8
+ tokenizer = AutoTokenizer.from_pretrained("csebuetnlp/mT5_multilingual_XLSum")
9
+ model_summarizer = AutoModelForSeq2SeqLM.from_pretrained("csebuetnlp/mT5_multilingual_XLSum")
10
+
11
+ def transcribe_and_summarize(audio_path):
12
+ # تحويل الصوت إلى نص
13
+ result = model_whisper.transcribe(audio_path)
14
+ text = result["text"]
15
+
16
+ # تلخيص النص
17
+ inputs = tokenizer("summarize: " + text, return_tensors="pt", max_length=512, truncation=True)
18
+ summary_ids = model_summarizer.generate(inputs["input_ids"], max_length=150, min_length=40, length_penalty=2.0, num_beams=4)
19
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
20
+
21
+ # إنشاء خريطة ذهنية بسيطة
22
+ mindmap = "🧠 الخريطة الذهنية:\n"
23
+ for i, sentence in enumerate(summary.split(".")):
24
+ if sentence.strip():
25
+ mindmap += f"- {sentence.strip()}\n"
26
+
27
+ return text, summary, mindmap
28
+
29
+ interface = gr.Interface(
30
+ fn=transcribe_and_summarize,
31
+ inputs=gr.Audio(source="upload", type="filepath", label="🎙️ ارفع ملف صوتي للدرس"),
32
+ outputs=[
33
+ gr.Textbox(label="📜 النص الكامل"),
34
+ gr.Textbox(label="✂️ الملخص"),
35
+ gr.Textbox(label="🧠 الخريطة الذهنية")
36
+ ],
37
+ title="SmartLessonMap - من الصوت إلى خريطة ذهنية",
38
+ description="🗣️ قم برفع تسجيل صوتي، وسيتم استخراج النص، تلخيصه، وتحويله إلى خريطة ذهنية!"
39
+ )
40
+
41
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch
4
+ openai-whisper