import gradio as gr import os import json import requests import time # AssemblyAI transcript endpoint (where we submit the file) transcript_endpoint = "https://api.assemblyai.com/v2/transcript" def get_transcript_url(url, api_token): headers={ "Authorization": api_token, "Content-Type": "application/json" } # JSON that tells the API which file to trancsribe json={"audio_url": url} response = requests.post( transcript_endpoint, json=json, headers=headers # Authorization to link this transcription with your account ) polling_endpoint = f"https://api.assemblyai.com/v2/transcript/{response.json()['id']}" while True: transcription_result = requests.get(polling_endpoint, headers=headers).json() if transcription_result['status'] == 'completed': break elif transcription_result['status'] == 'error': raise RuntimeError(f"Transcription failed: {transcription_result['error']}") else: time.sleep(3) return transcription_result['text'] title = """

🔥Conformer-1 API

""" description = """ In this demo, you can explore the outputs of a Conformer-1 Speech Recognition Model from AssemblyAI. """ with gr.Blocks(css = """#col_container {width: 1000px; margin-left: auto; margin-right: auto;} """) as demo: gr.HTML(title) with gr.Column(elem_id = "col_container"): assemblyai_api_key = gr.Textbox(type='password', label="Enter your AssemblyAI API key here") inputs = gr.Textbox(label = "Enter the url for the audio file") transcript = gr.Textbox(label = "Transcript Result" ) b1 = gr.Button() inputs.submit(get_transcript_url, [inputs, assemblyai_api_key], [transcript]) b1.click(get_transcript_url, [inputs, assemblyai_api_key], [transcript]) #gr.Markdown(description) demo.queue().launch(debug=True)