Spaces:
Running on Zero
Running on Zero
| import spaces | |
| import gradio as gr | |
| import os | |
| import httpx | |
| 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() |