Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
from langdetect import detect | |
asr = pipeline("automatic-speech-recognition", model="openai/whisper-small") | |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
def process_audio(audio_path): | |
if not audio_path or isinstance(audio_path, bool): | |
return "No audio file provided.", "", "", "" | |
try: | |
result = asr(audio_path) | |
transcript = result["text"] | |
except Exception as e: | |
return f"Error in transcription: {e}", "", "", "" | |
try: | |
detected_lang = detect(transcript) | |
except Exception: | |
detected_lang = "unknown" | |
lang_map = {'en': 'English', 'hi': 'Hindi', 'ta': 'Tamil'} | |
lang_text = lang_map.get(detected_lang, detected_lang) | |
transcript_en = transcript | |
if detected_lang != "en": | |
try: | |
result_translate = asr(audio_path, generate_kwargs={"task": "translate"}) | |
transcript_en = result_translate["text"] | |
except Exception as e: | |
transcript_en = f"Error translating: {e}" | |
try: | |
summary = summarizer(transcript_en, max_length=100, min_length=30, do_sample=False) | |
summary_text = summary[0]["summary_text"] | |
except Exception as e: | |
summary_text = f"Error summarizing: {e}" | |
return lang_text, transcript, transcript_en, summary_text | |
iface = gr.Interface( | |
fn=process_audio, | |
inputs=gr.Audio(source="upload", type="filepath", label="Upload MP3/WAV Audio"), | |
outputs=[ | |
gr.Textbox(label="Detected Language"), | |
gr.Textbox(label="Original Transcript"), | |
gr.Textbox(label="English Transcript (if translated)"), | |
gr.Textbox(label="Summary"), | |
], | |
title="Audio Transcript, Translation & Summary", | |
description="Upload your audio file (MP3/WAV). This app transcribes, detects language, translates to English if needed, and summarizes." | |
) | |
iface.launch() | |