CoolFace
Apppublic

aliyaasif/Audio-Video-To-Text

sourceHugging Faceupdated 2mo agoView on Hugging Face
1likes
app.py42 linesDownload Raw Back to root
1import spaces2import gradio as gr3import os4import httpx5 6@spaces.GPU(duration=0)7def transcribe(audio_path):8    if audio_path is None:9        return "Please upload an audio file."10    11    api_key = os.environ.get("ELEVENLABS_API_KEY")12    if not api_key:13        return "ERROR: ELEVENLABS_API_KEY not found!"14    15    try:16        with open(audio_path, "rb") as audio_file:17            response = httpx.post(18                "https://api.elevenlabs.io/v1/speech-to-text",19                headers={"xi-api-key": api_key},20                files={"file": audio_file},21                data={"model_id": "scribe_v1"},22                timeout=12023            )24        25        if response.status_code == 200:26            result = response.json()27            return result.get("text", "No text found")28        else:29            return f"ERROR {response.status_code}: {response.text}"30            31    except Exception as e:32        return f"ERROR: {str(e)}"33 34demo = gr.Interface(35    fn=transcribe,36    inputs=gr.Audio(type="filepath"),37    outputs=gr.Textbox(lines=20),38    title="Audio Transcription - ElevenLabs Scribe",39    description="Upload audio for accurate transcription."40)41 42demo.launch()