gooya-asr / app.py
funlifew's picture
use "with" statement for more safety (it's my opinion)
b36a0c9 verified
raw
history blame
1.83 kB
import gradio as gr
import requests
import os
import time
# Retrieve ASR API URL and Authorization Token from environment variables
ASR_API_URL = os.getenv('ASR_API_URL')
AUTH_TOKEN = os.getenv('AUTH_TOKEN')
def transcribe_audio(file_path):
if not ASR_API_URL or not AUTH_TOKEN:
return "Error: Missing ASR_API_URL or AUTH_TOKEN.", None
headers = {
'Accept': 'application/json',
'Authorization': f'Bearer {AUTH_TOKEN}',
}
try:
with open(file_path, 'rb') as audio_file:
files = {'file': (file_path, audio_file, 'audio/mpeg')}
start_time = time.time()
response = requests.post(ASR_API_URL, headers=headers, files=files)
elapsed_time = time.time() - start_time
if response.ok:
data = response.json()
transcription = data.get('transcription', 'No transcription returned.')
inference_time = f"{data.get('time', round(elapsed_time, 2))} seconds"
return transcription, inference_time
else:
return f"Error: {response.status_code}, {response.text}", None
except Exception as e:
return f"Exception occurred: {str(e)}", None
# Set up the Gradio interface
gr.Interface(
fn=transcribe_audio,
inputs=gr.Audio(type="filepath"),
outputs=[
gr.Textbox(label="Transcription"),
gr.Textbox(label="Inference Time")
],
title="Gooya v1.4 Persian ASR",
description="""
The Gooya Persian ASR model is crazy fast and super [powerful](https://huggingface.co/spaces/navidved/open_persian_asr_leaderboard) when it comes to Persian ASR!
\nJust drop in a Persian audio file, and boom—we’ll hit you with the best transcription you can get! 🚀🔥
\n(The maximum time allowed for testing is 30 seconds.)
"""
).launch()