Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
import json
|
4 |
|
5 |
def extract_words(json_data):
|
@@ -7,15 +7,26 @@ def extract_words(json_data):
|
|
7 |
return ''.join(words)
|
8 |
|
9 |
def transcribe_audio(file):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
file
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
iface = gr.Interface(
|
21 |
fn=transcribe_audio,
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
import json
|
4 |
|
5 |
def extract_words(json_data):
|
|
|
7 |
return ''.join(words)
|
8 |
|
9 |
def transcribe_audio(file):
|
10 |
+
api_key = "sk-proj-6J4EfDKmIduACsB38LXlT3BlbkFJSVTYDzfbVeAvbKHp1l1z"
|
11 |
+
url = "https://api.openai.com/v1/audio/transcriptions"
|
12 |
+
headers = {
|
13 |
+
"Authorization": f"Bearer {api_key}"
|
14 |
+
}
|
15 |
+
files = {
|
16 |
+
"file": file,
|
17 |
+
"model": (None, "whisper-1"),
|
18 |
+
"language": (None, "ja"),
|
19 |
+
"response_format": (None, "verbose_json"),
|
20 |
+
"timestamp_granularities": (None, "word")
|
21 |
+
}
|
22 |
+
|
23 |
+
response = requests.post(url, headers=headers, files=files)
|
24 |
+
response_json = response.json()
|
25 |
+
|
26 |
+
if "words" in response_json:
|
27 |
+
return extract_words(response_json['words'])
|
28 |
+
else:
|
29 |
+
return "Error in transcription: " + response_json.get("error", {}).get("message", "Unknown error")
|
30 |
|
31 |
iface = gr.Interface(
|
32 |
fn=transcribe_audio,
|