gooya-asr / app.py
funlifew's picture
Introduced a clean and user-friendly Gradio interface for the Gooya Persian ASR system
cd7d7b1 verified
raw
history blame
2.04 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
# Prepare headers and data
headers = {
'accept': 'application/json',
'Authorization': f'Bearer {AUTH_TOKEN}',
}
files = {
'file': (file_path, open(file_path, 'rb'), 'audio/mpeg'),
}
start_time = time.time()
# Send POST request
response = requests.post(ASR_API_URL, headers=headers, files=files)
inference_time = time.time() - start_time # in seconds
# Check if response is successful
if response.status_code == 200:
transcription = response.json().get("transcription", "No transcription returned.")
inference_time_str = f"{response.json().get('time', 'No inference time returned.')} seconds"
return transcription, inference_time_str
else:
return f"Error: {response.status_code}, {response.text}", None
# Set up the Gradio interface
def launch_interface():
gr.Interface(
fn=transcribe_audio,
inputs=gr.Audio(type="filepath", label="Upload Audio (Max 30s)"),
outputs=[
gr.Textbox(label="πŸ“ Transcription"),
gr.Textbox(label="⏱️ Inference Time (s)")
],
title="πŸ—£οΈ Gooya v1.4 – Persian ASR",
description=(
"The **Gooya Persian ASR** model is crazy fast and incredibly [powerful]"
"(https://huggingface.co/spaces/navidved/open_persian_asr_leaderboard) "
"when it comes to Persian speech recognition!\n\n"
"🎀 Just drop a short Persian audio clip (max 30s), and boom β€” "
"you’ll get a top-notch transcription instantly. πŸš€πŸ”₯"
),
theme="default",
allow_flagging="never"
).launch()
launch_interface()