File size: 1,010 Bytes
cf75eeb
b789fdf
cf75eeb
b789fdf
cf75eeb
 
 
 
 
b789fdf
cf75eeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import whisper
import gradio as gr
from transformers import pipeline

# Load models
def transcribe_audio(file_path):
    model = whisper.load_model("base")  # Use "tiny", "base", "small", etc.
    result = model.transcribe(file_path)
    return result["text"]

def extract_topics(text):
    summarizer = pipeline("summarization")
    summary = summarizer(text, max_length=50, min_length=25, do_sample=False)
    return summary[0]["summary_text"]

def process_audio(file):
    # Transcribe the audio file
    transcript = transcribe_audio(file.name)
    # Extract topics from the transcription
    topics = extract_topics(transcript)
    return transcript, topics

# Gradio interface
interface = gr.Interface(
    fn=process_audio,
    inputs=gr.Audio(source="upload", type="filepath"),
    outputs=["text", "text"],
    title="Audio Transcription and Topic Extraction",
    description="Upload an audio file to get a transcription and extract main topics."
)

if __name__ == "__main__":
    interface.launch()