|
import gradio as gr |
|
import os |
|
from transformers import pipeline |
|
|
|
|
|
asr = pipeline(task="automatic-speech-recognition", model="distil-whisper/distil-small.en") |
|
|
|
|
|
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") |
|
|
|
|
|
def transcribe_and_summarize(audio_file): |
|
if audio_file is None: |
|
return "Error: No audio file provided.", "" |
|
|
|
try: |
|
|
|
transcription_result = asr(audio_file, return_timestamps=True) |
|
|
|
|
|
transcribed_text = " ".join([segment['text'] for segment in transcription_result['chunks']]) |
|
|
|
|
|
if len(transcribed_text.split()) < 50: |
|
summarized_text = "Text too short to summarize." |
|
else: |
|
|
|
summary_result = summarizer(transcribed_text, max_length=100, min_length=30, do_sample=False) |
|
summarized_text = summary_result[0]['summary_text'] |
|
|
|
return transcribed_text, summarized_text |
|
|
|
except Exception as e: |
|
return f"Error: {str(e)}", "" |
|
|
|
|
|
iface = gr.Interface( |
|
fn=transcribe_and_summarize, |
|
inputs=gr.Audio(type="filepath"), |
|
outputs=[ |
|
gr.Textbox(label="Transcribed Text"), |
|
gr.Textbox(label="Summarized Text") |
|
] |
|
) |
|
|
|
|
|
port = int(os.environ.get('PORT1', 7860)) |
|
|
|
|
|
iface.launch(share=True, server_port=port) |
|
|