Spaces:
Runtime error
Runtime error
RamAnanth1
commited on
Commit
·
830a45d
1
Parent(s):
8783cef
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import json
|
4 |
+
import requests
|
5 |
+
import time
|
6 |
+
|
7 |
+
# AssemblyAI transcript endpoint (where we submit the file)
|
8 |
+
transcript_endpoint = "https://api.assemblyai.com/v2/transcript"
|
9 |
+
|
10 |
+
def get_transcript_url(url, api_token):
|
11 |
+
headers={
|
12 |
+
"Authorization": api_token,
|
13 |
+
"Content-Type": "application/json"
|
14 |
+
}
|
15 |
+
# JSON that tells the API which file to trancsribe
|
16 |
+
json={"audio_url": url}
|
17 |
+
|
18 |
+
response = requests.post(
|
19 |
+
transcript_endpoint,
|
20 |
+
json=json,
|
21 |
+
headers=headers # Authorization to link this transcription with your account
|
22 |
+
)
|
23 |
+
|
24 |
+
polling_endpoint = f"https://api.assemblyai.com/v2/transcript/{response.json()['id']}"
|
25 |
+
while True:
|
26 |
+
transcription_result = requests.get(polling_endpoint, headers=headers).json()
|
27 |
+
if transcription_result['status'] == 'completed':
|
28 |
+
break
|
29 |
+
elif transcription_result['status'] == 'error':
|
30 |
+
raise RuntimeError(f"Transcription failed: {transcription_result['error']}")
|
31 |
+
else:
|
32 |
+
time.sleep(3)
|
33 |
+
return transcription_result['text']
|
34 |
+
|
35 |
+
title = """<h1 align="center">🔥Conformer-1 API </h1>"""
|
36 |
+
description = """
|
37 |
+
In this demo, you can explore the outputs of a Conformer-1 Speech Recognition Model from AssemblyAI.
|
38 |
+
"""
|
39 |
+
|
40 |
+
with gr.Blocks(css = """#col_container {width: 1000px; margin-left: auto; margin-right: auto;}
|
41 |
+
""") as demo:
|
42 |
+
gr.HTML(title)
|
43 |
+
with gr.Column(elem_id = "col_container"):
|
44 |
+
assemblyai_api_key = gr.Textbox(type='password', label="Enter your AssemblyAI API key here")
|
45 |
+
inputs = gr.Textbox(label = "Enter the url for the audio file")
|
46 |
+
transcript = gr.Textbox(label = "Transcript Result" )
|
47 |
+
|
48 |
+
b1 = gr.Button()
|
49 |
+
|
50 |
+
inputs.submit(get_transcript_url, [inputs, assemblyai_api_key], [transcript])
|
51 |
+
b1.click(get_transcript_url, [inputs, assemblyai_api_key], [transcript])
|
52 |
+
|
53 |
+
#gr.Markdown(description)
|
54 |
+
demo.queue().launch(debug=True)
|
55 |
+
|