ilsa15 commited on
Commit
de09164
·
verified ·
1 Parent(s): 43c5423

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -6
app.py CHANGED
@@ -1,3 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import whisper
3
  import os
@@ -11,9 +70,6 @@ MODEL_NAME = "llama3-8b-8192"
11
  # 🎙 Load Whisper
12
  transcriber = whisper.load_model("base")
13
 
14
- inputs=gr.Audio(source="microphone", type="filepath", label="🎙️ Speak Now or Upload Audio"),
15
-
16
-
17
  def transcribe_and_summarize(audio):
18
  # Step 1: Transcribe + Detect Language
19
  result = transcriber.transcribe(audio)
@@ -44,17 +100,17 @@ def transcribe_and_summarize(audio):
44
 
45
  return f"[{lang_label}] {transcript}", f"[{lang_label}] {summary}"
46
 
 
47
  demo = gr.Interface(
48
  fn=transcribe_and_summarize,
49
- inputs=gr.Audio(type="filepath", label="🎧 Upload Audio (English or Urdu)"),
50
  outputs=[
51
  gr.Textbox(label="📝 Transcript"),
52
  gr.Textbox(label="🧠 Summary")
53
  ],
54
  title="🗣️ Multilingual Audio Summarizer",
55
- description="Upload English or Urdu audio. The app transcribes and summarizes in the same language using Whisper + Groq."
56
  )
57
 
58
  demo.launch()
59
 
60
-
 
1
+ # import gradio as gr
2
+ # import whisper
3
+ # import os
4
+ # from groq import Groq
5
+
6
+ # # 🔐 Get Groq API key securely from Hugging Face Secrets
7
+ # GROQ_API_KEY = os.getenv("GROQ_API_KEY")
8
+ # groq_client = Groq(api_key=GROQ_API_KEY)
9
+ # MODEL_NAME = "llama3-8b-8192"
10
+
11
+ # # 🎙 Load Whisper
12
+ # transcriber = whisper.load_model("base")
13
+
14
+
15
+
16
+
17
+ # def transcribe_and_summarize(audio):
18
+ # # Step 1: Transcribe + Detect Language
19
+ # result = transcriber.transcribe(audio)
20
+ # transcript = result["text"]
21
+ # detected_lang = result["language"]
22
+
23
+ # # Step 2: Summarize in the same language
24
+ # if detected_lang == "en":
25
+ # system_prompt = "You are an expert English summarizer."
26
+ # user_prompt = f"Please summarize the following English text:\n\n{transcript}"
27
+ # elif detected_lang == "ur":
28
+ # system_prompt = "آپ ایک ماہر خلاصہ نگار ہیں جو اردو میں خلاصہ فراہم کرتے ہیں۔"
29
+ # user_prompt = f"براہ کرم مندرجہ ذیل اردو متن کا خلاصہ فراہم کریں:\n\n{transcript}"
30
+ # else:
31
+ # system_prompt = "You are a helpful summarizer."
32
+ # user_prompt = f"Summarize this text:\n\n{transcript}"
33
+
34
+ # response = groq_client.chat.completions.create(
35
+ # model=MODEL_NAME,
36
+ # messages=[
37
+ # {"role": "system", "content": system_prompt},
38
+ # {"role": "user", "content": user_prompt}
39
+ # ]
40
+ # )
41
+ # summary = response.choices[0].message.content.strip()
42
+
43
+ # lang_label = "English" if detected_lang == "en" else "Urdu" if detected_lang == "ur" else detected_lang.upper()
44
+
45
+ # return f"[{lang_label}] {transcript}", f"[{lang_label}] {summary}"
46
+
47
+ # demo = gr.Interface(
48
+ # fn=transcribe_and_summarize,
49
+ # inputs=gr.Audio(type="filepath", label="🎧 Upload Audio (English or Urdu)"),
50
+ # outputs=[
51
+ # gr.Textbox(label="📝 Transcript"),
52
+ # gr.Textbox(label="🧠 Summary")
53
+ # ],
54
+ # title="🗣️ Multilingual Audio Summarizer",
55
+ # description="Upload English or Urdu audio. The app transcribes and summarizes in the same language using Whisper + Groq."
56
+ # )
57
+
58
+ # demo.launch()
59
+
60
  import gradio as gr
61
  import whisper
62
  import os
 
70
  # 🎙 Load Whisper
71
  transcriber = whisper.load_model("base")
72
 
 
 
 
73
  def transcribe_and_summarize(audio):
74
  # Step 1: Transcribe + Detect Language
75
  result = transcriber.transcribe(audio)
 
100
 
101
  return f"[{lang_label}] {transcript}", f"[{lang_label}] {summary}"
102
 
103
+ # ✅ Enable microphone + upload support
104
  demo = gr.Interface(
105
  fn=transcribe_and_summarize,
106
+ inputs=gr.Audio(source="microphone", type="filepath", label="🎙️ Speak or Upload Audio (English/Urdu)"),
107
  outputs=[
108
  gr.Textbox(label="📝 Transcript"),
109
  gr.Textbox(label="🧠 Summary")
110
  ],
111
  title="🗣️ Multilingual Audio Summarizer",
112
+ description="🎙️ Speak directly or upload an English/Urdu audio file. This app transcribes and summarizes using Whisper + Groq (LLaMA3)."
113
  )
114
 
115
  demo.launch()
116