gooya-asr / app.py
navidved's picture
Update app.py
8178007 verified
raw
history blame
1.8 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."
# 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:
return response.json().get("transcription", "No transcription returned.")
else:
return f"Error: {response.status_code}, {response.text}"
description_text = """
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!
๐Ÿš€๐Ÿ”ฅ Just drop in a Persian audio file, and boomโ€”weโ€™ll hit you with the best transcription you can get! ๐Ÿš€๐Ÿ”ฅ
"""
# Set up the Gradio interface
gr.Interface(
fn=transcribe_audio,
inputs=gr.Audio(type="filepath"), # Updated here
outputs="text",
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!
๐Ÿš€๐Ÿ”ฅ Just drop in a Persian audio file, and boomโ€”weโ€™ll hit you with the best transcription you can get! ๐Ÿš€๐Ÿ”ฅ
"""
).launch()