Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import whisper
|
3 |
+
from transformers import pipeline
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
# Load Whisper model for transcription
|
7 |
+
whisper_model = whisper.load_model("base")
|
8 |
+
|
9 |
+
# Load BART model for summarization
|
10 |
+
summarization = pipeline("summarization", model="facebook/bart-large-cnn")
|
11 |
+
|
12 |
+
def process_audio(audio_file, min_length, max_length):
|
13 |
+
try:
|
14 |
+
# Transcribe audio to text
|
15 |
+
result = whisper_model.transcribe(audio_file)
|
16 |
+
text = result['text']
|
17 |
+
|
18 |
+
# Summarize the transcript
|
19 |
+
summary_result = summarization(text, max_length=max_length, min_length=min_length)
|
20 |
+
summary = summary_result[0]['summary_text']
|
21 |
+
|
22 |
+
# Save results to CSV
|
23 |
+
df_results = pd.DataFrame({
|
24 |
+
"Audio File": [audio_file],
|
25 |
+
"Transcript": [text],
|
26 |
+
"Summary": [summary]
|
27 |
+
})
|
28 |
+
df_results.to_csv("results.csv", index=False)
|
29 |
+
|
30 |
+
return text, summary
|
31 |
+
|
32 |
+
except Exception as e:
|
33 |
+
return f"Error: {str(e)}", ""
|
34 |
+
|
35 |
+
# Define Gradio interface
|
36 |
+
iface = gr.Interface(
|
37 |
+
fn=process_audio,
|
38 |
+
inputs=[
|
39 |
+
gr.Audio(sources="upload", type="filepath", label="Upload your audio file"),
|
40 |
+
gr.Slider(minimum=5, maximum=50, value=30, label="Minimum Summary Length"),
|
41 |
+
gr.Slider(minimum=50, maximum=500, value=150, label="Maximum Summary Length")
|
42 |
+
],
|
43 |
+
outputs=[
|
44 |
+
gr.Textbox(label="Transcript"),
|
45 |
+
gr.Textbox(label="Summary")
|
46 |
+
],
|
47 |
+
title="Audio to Summarized Transcript",
|
48 |
+
description="Upload an audio file and adjust summary length to get both the transcript and summary."
|
49 |
+
)
|
50 |
+
|
51 |
+
# Launch the Gradio interface
|
52 |
+
iface.launch()
|