ArabicASRNvidia / app.py
101Frost's picture
Update app.py
5f2dcb0 verified
import gradio as gr
import requests
# API endpoints with model names
NVIDIA_CONFORMER_API = "http://8.213.40.255/transcribe" # nvidia-conformer-ctc-large-arabic
OPENAI_WHISPER_API = "http://8.213.32.123/transcribe?language=ar&task=transcribe&word_timestamps=false" # openai-whisper-large-v3
def process_audio(audio_file):
result_conformer = "No response from NVIDIA Conformer API"
result_whisper = "No response from OpenAI Whisper API"
try:
with open(audio_file, "rb") as f:
files = {"audio_file": f}
response = requests.post(NVIDIA_CONFORMER_API, files=files)
if response.status_code == 200:
try:
data = response.json()
transcription = data.get("transcription", "No transcription found")
result_conformer = f"πŸ“ NVIDIA Conformer Transcription: {transcription}"
except ValueError:
result_conformer = f"⚠️ NVIDIA Conformer could not parse JSON: {response.text}"
else:
result_conformer = f"❌ NVIDIA Conformer Error: {response.status_code} - {response.text}"
except Exception as e:
result_conformer = f"⚠️ NVIDIA Conformer Exception: {str(e)}"
try:
with open(audio_file, "rb") as f:
files = {"file": (audio_file, f, "audio/wav")}
headers = {"accept": "application/json"}
response = requests.post(OPENAI_WHISPER_API, files=files, headers=headers)
if response.status_code == 200:
try:
data = response.json()
text = data.get("text", "No text found")
result_whisper = f"πŸ“ OpenAI Whisper Transcription: {text}"
except ValueError:
result_whisper = f"⚠️ OpenAI Whisper could not parse JSON: {response.text}"
else:
result_whisper = f"❌ OpenAI Whisper Error: {response.status_code} - {response.text}"
except Exception as e:
result_whisper = f"⚠️ OpenAI Whisper Exception: {str(e)}"
return result_conformer, result_whisper
# Gradio UI
with gr.Blocks() as demo:
gr.Markdown("## 🎀 Record Audio and Send to NVIDIA Conformer & OpenAI Whisper APIs")
with gr.Row():
audio_input = gr.Audio(sources=["microphone"], type="filepath")
with gr.Row():
output_conformer = gr.Textbox(label="NVIDIA Conformer API Response")
output_whisper = gr.Textbox(label="OpenAI Whisper API Response")
submit_btn = gr.Button("Send to APIs")
submit_btn.click(process_audio, inputs=audio_input, outputs=[output_conformer, output_whisper])
if __name__ == "__main__":
demo.launch()