Spaces:
Running on Zero
Running on Zero
File size: 1,197 Bytes
41f4d1b ec0f7db 335d62d 033f497 acb5575 41f4d1b acb5575 033f497 888317f 033f497 844b79c 033f497 ec0f7db acb5575 033f497 ec0f7db 335d62d | 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 35 36 37 38 39 40 41 42 | import spaces
import gradio as gr
import os
import httpx
@spaces.GPU(duration=0)
def transcribe(audio_path):
if audio_path is None:
return "Please upload an audio file."
api_key = os.environ.get("ELEVENLABS_API_KEY")
if not api_key:
return "ERROR: ELEVENLABS_API_KEY not found!"
try:
with open(audio_path, "rb") as audio_file:
response = httpx.post(
"https://api.elevenlabs.io/v1/speech-to-text",
headers={"xi-api-key": api_key},
files={"file": audio_file},
data={"model_id": "scribe_v1"},
timeout=120
)
if response.status_code == 200:
result = response.json()
return result.get("text", "No text found")
else:
return f"ERROR {response.status_code}: {response.text}"
except Exception as e:
return f"ERROR: {str(e)}"
demo = gr.Interface(
fn=transcribe,
inputs=gr.Audio(type="filepath"),
outputs=gr.Textbox(lines=20),
title="Audio Transcription - ElevenLabs Scribe",
description="Upload audio for accurate transcription."
)
demo.launch() |