File size: 1,977 Bytes
830a45d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8963f6c
830a45d
 
6b46d12
830a45d
6b46d12
830a45d
 
 
 
8963f6c
830a45d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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 = """<h1 align="center">🔥Conformer-1 API </h1>"""
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)
    gr.Markdown(description)
    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")        
        b1 = gr.Button()
        transcript = gr.Textbox(label = "Transcript Result" )
    
    inputs.submit(get_transcript_url, [inputs, assemblyai_api_key], [transcript])
    b1.click(get_transcript_url, [inputs, assemblyai_api_key], [transcript])
                    
    
    demo.queue().launch(debug=True)