afiz commited on
Commit
823b2ec
·
1 Parent(s): 6a04956

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from pprint import pprint
3
+ from time import sleep
4
+
5
+ api_key = 'f903a9f5a28f484f8f286fb2b782eb23'
6
+ audio_url = 'https://listentogenius.com/recordings4/Innocence.mp3'
7
+
8
+ def audio_to_text(api_key, audio_url):
9
+ endpoint = "https://api.assemblyai.com/v2/transcript"
10
+
11
+ headers = {
12
+ 'authorization': api_key,
13
+ 'content-type': 'application/json'
14
+ }
15
+
16
+ body = {
17
+ 'audio_url': audio_url
18
+ }
19
+
20
+ # 1. Submitting Files for Transcription
21
+
22
+ res = requests.post(endpoint, json=body, headers=headers)
23
+ transcript_id = res.json().get('id')
24
+ print(transcript_id)
25
+
26
+ # 2. Getting the Transcription Result
27
+
28
+ endpoint_full = f"https://api.assemblyai.com/v2/transcript/{transcript_id}"
29
+ status = 'processing'
30
+ while transcript_id and status != 'completed':
31
+ print('Getting the transcription result ....')
32
+ sleep(5)
33
+ res_text = requests.get(endpoint_full, headers=headers)
34
+ status = res_text.json().get('status')
35
+ data = res_text.json().get('text')
36
+
37
+ return data
38
+
39
+
40
+ import gradio as gr
41
+
42
+ demo = gr.Blocks()
43
+
44
+ with demo:
45
+ gr.Markdown(
46
+ """
47
+ # Convert Audio files to Text files using AssemblyAI.
48
+ ### Get AssemblyAI API Key from here assemblyai.com
49
+ """)
50
+ inp = [gr.Textbox(label='API Key', placeholder="What is your API Key?"), gr.Textbox(label='Audio File URL', placeholder="Audio file URL?")]
51
+ out = gr.Textbox(label='Output')
52
+ text_button = gr.Button("Flip")
53
+
54
+ text_button.click(audio_to_text, inputs=inp, outputs=out)
55
+
56
+ demo.launch()