ronniet commited on
Commit
2176d40
·
1 Parent(s): e30c131

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -36
app.py CHANGED
@@ -18,43 +18,65 @@ import gradio as gr
18
  # demo.launch()
19
 
20
 
21
- import requests
22
- import time
23
- import tempfile
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  import os
 
25
 
26
- token = os.environ['apikey']
27
- #discord_id = os.environ['discord-id']
28
- API_HOST = "https://labs-proxy.voicemod.net/"
29
-
30
- def download_file(url):
31
- response = requests.get(url)
32
- if response.status_code == 200:
33
- with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
34
- tmp_file.write(response.content)
35
- tmp_file.flush()
36
- return tmp_file.name
37
- else:
38
- print("Error: Unable to download file")
39
-
40
- def tts(text):
41
- url = API_HOST + "api/v1/tts/create"
42
- payload = {
43
- "text": text[:200] if len(text) > 200 else text,
44
- "voiceId": "6926ecc5-ff5e-47c6-912b-3ffdb880bf56" # Narrator
45
- }
46
- headers = {
47
- 'x-api-key': token,
48
- }
49
- response = requests.request("POST", url, headers=headers, json=payload)
50
- jsonResp = response.json()
51
-
52
- return gr.make_waveform(download_file(jsonResp['audioUrl']))
53
-
54
- demo = gr.Interface(
55
- fn=tts,
56
- inputs="text",
57
- outputs="audio"
58
  )
59
 
60
- demo.launch()
 
 
18
  # demo.launch()
19
 
20
 
21
+ # import requests
22
+ # import time
23
+ # import tempfile
24
+ # import os
25
+
26
+ # token = os.environ['apikey']
27
+ # #discord_id = os.environ['discord-id']
28
+ # API_HOST = "https://labs-proxy.voicemod.net/"
29
+
30
+ # def download_file(url):
31
+ # response = requests.get(url)
32
+ # if response.status_code == 200:
33
+ # with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
34
+ # tmp_file.write(response.content)
35
+ # tmp_file.flush()
36
+ # return tmp_file.name
37
+ # else:
38
+ # print("Error: Unable to download file")
39
+
40
+ # def tts(text):
41
+ # url = API_HOST + "api/v1/tts/create"
42
+ # payload = {
43
+ # "text": text[:200] if len(text) > 200 else text,
44
+ # "voiceId": "6926ecc5-ff5e-47c6-912b-3ffdb880bf56" # Narrator
45
+ # }
46
+ # headers = {
47
+ # 'x-api-key': token,
48
+ # }
49
+ # response = requests.request("POST", url, headers=headers, json=payload)
50
+ # jsonResp = response.json()
51
+
52
+ # return gr.make_waveform(download_file(jsonResp['audioUrl']))
53
+
54
+ # demo = gr.Interface(
55
+ # fn=tts,
56
+ # inputs="text",
57
+ # outputs="audio"
58
+ # )
59
+
60
+ # demo.launch()
61
+
62
+ import openai
63
  import os
64
+ #from pymongo import MongoClient
65
 
66
+ api_key = os.environ.get("OPENAI_API_KEY")
67
+
68
+ def transcribe_audio(filepath):
69
+ audio = open(filepath, "rb")
70
+ transcript = openai.Audio.transcribe("whisper-1", audio)
71
+ return transcript['text']
72
+
73
+
74
+ # Create a Gradio Tabbed Interface
75
+ iface = gr.Interface(
76
+ fn=transcribe_audio,
77
+ inputs= gr.Audio(source="upload", type="filepath"),
78
+ outputs="text",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  )
80
 
81
+
82
+ iface.launch()