madanyc commited on
Commit
f2638b8
·
1 Parent(s): 16f50dd

Initial Code Commit

Browse files
Files changed (2) hide show
  1. app.py +49 -3
  2. requirements.txt +3 -0
app.py CHANGED
@@ -1,7 +1,53 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base")
5
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
6
+
7
+
8
+ def transcribe(audio):
9
+ if audio is None:
10
+ return "", ""
11
+ result = transcriber(audio)
12
+ text = result["text"]
13
+ return text, ""
14
+
15
+
16
+ def summarize(text):
17
+ if not text or not text.strip():
18
+ return "No text to summarize."
19
+ if len(text.split()) < 30:
20
+ return "Text is too short to summarize."
21
+ summary = summarizer(text, max_length=130, min_length=30, do_sample=False)
22
+ return summary[0]["summary_text"]
23
+
24
+
25
+ with gr.Blocks(title="Audio Transcription & Summary") as demo:
26
+ gr.Markdown("# 🎙️ Audio Transcription & Summary")
27
+ gr.Markdown("Upload or record audio to transcribe it, then generate a summary.")
28
+
29
+ with gr.Row():
30
+ audio_input = gr.Audio(type="filepath", label="Upload or Record Audio")
31
+
32
+ with gr.Row():
33
+ transcribe_btn = gr.Button("Transcribe", variant="primary")
34
+
35
+ transcription_output = gr.Textbox(label="Transcription", lines=10)
36
+
37
+ with gr.Row():
38
+ summarize_btn = gr.Button("Summarize", variant="secondary")
39
+
40
+ summary_output = gr.Textbox(label="Summary", lines=5)
41
+
42
+ transcribe_btn.click(
43
+ fn=transcribe,
44
+ inputs=audio_input,
45
+ outputs=[transcription_output, summary_output],
46
+ )
47
+ summarize_btn.click(
48
+ fn=summarize,
49
+ inputs=transcription_output,
50
+ outputs=summary_output,
51
+ )
52
 
 
53
  demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio