Spaces:
Sleeping
Sleeping
v4
Browse files
app.py
CHANGED
@@ -8,19 +8,19 @@ headers = {
|
|
8 |
'accept': 'application/json',
|
9 |
'x-gladia-key': '89b0adf5-fb2c-48ba-8a66-76b02827fd14',
|
10 |
# requests won't add a boundary if this header is set when you pass files=
|
11 |
-
'Content-Type': 'multipart/form-data',
|
12 |
}
|
13 |
|
14 |
|
15 |
-
openai_key = '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'
|
16 |
|
17 |
-
|
|
|
|
|
|
|
18 |
'Content-Type': 'application/json',
|
19 |
'Authorization': f'Bearer {openai_key}',
|
20 |
|
21 |
}
|
22 |
-
|
23 |
-
def create(prompt):
|
24 |
data = {
|
25 |
"model": "text-davinci-003",
|
26 |
"prompt": prompt,
|
@@ -36,7 +36,7 @@ def create(prompt):
|
|
36 |
return r.json()
|
37 |
|
38 |
|
39 |
-
def convert(res):
|
40 |
data = res.json()
|
41 |
prediction = data['prediction']
|
42 |
content = []
|
@@ -45,7 +45,7 @@ def convert(res):
|
|
45 |
auido_txt = '\n'.join(content)
|
46 |
|
47 |
prompt = f"将下面的内容,总结10条要点出来,\n{auido_txt}"
|
48 |
-
open_ai_res = create(prompt)
|
49 |
answer = open_ai_res['choices'][0]['text']
|
50 |
|
51 |
res_content = f'音频内容:\n{auido_txt}\nGPT3总结的要点:\n{answer}'
|
@@ -64,7 +64,7 @@ def get_audio(url):
|
|
64 |
print('aodio over ..')
|
65 |
return audio_file
|
66 |
|
67 |
-
def get_transcript(url):
|
68 |
audio_file = get_audio(url)
|
69 |
# audio_file = 'tmp.mp4'
|
70 |
files = {
|
@@ -74,7 +74,7 @@ def get_transcript(url):
|
|
74 |
}
|
75 |
response = requests.post('https://api.gladia.io/audio/text/audio-transcription/', headers=headers, files=files)
|
76 |
print(response.text)
|
77 |
-
return convert(response)
|
78 |
|
79 |
|
80 |
|
@@ -88,6 +88,7 @@ with gr.Blocks() as demo:
|
|
88 |
|
89 |
with gr.Row():
|
90 |
url = gr.Textbox(placeholder='Youtube video URL', label='URL')
|
|
|
91 |
|
92 |
|
93 |
with gr.Row():
|
@@ -97,6 +98,6 @@ with gr.Blocks() as demo:
|
|
97 |
with gr.Column():
|
98 |
outputs = gr.Textbox(placeholder='Transcription of the video', label='Transcription')
|
99 |
|
100 |
-
transcribe_btn.click(get_transcript, inputs=[url], outputs=outputs)
|
101 |
|
102 |
demo.launch(debug=True)
|
|
|
8 |
'accept': 'application/json',
|
9 |
'x-gladia-key': '89b0adf5-fb2c-48ba-8a66-76b02827fd14',
|
10 |
# requests won't add a boundary if this header is set when you pass files=
|
11 |
+
# 'Content-Type': 'multipart/form-data',
|
12 |
}
|
13 |
|
14 |
|
|
|
15 |
|
16 |
+
|
17 |
+
def create(prompt,openai_key):
|
18 |
+
|
19 |
+
headers = {
|
20 |
'Content-Type': 'application/json',
|
21 |
'Authorization': f'Bearer {openai_key}',
|
22 |
|
23 |
}
|
|
|
|
|
24 |
data = {
|
25 |
"model": "text-davinci-003",
|
26 |
"prompt": prompt,
|
|
|
36 |
return r.json()
|
37 |
|
38 |
|
39 |
+
def convert(res,openai_key):
|
40 |
data = res.json()
|
41 |
prediction = data['prediction']
|
42 |
content = []
|
|
|
45 |
auido_txt = '\n'.join(content)
|
46 |
|
47 |
prompt = f"将下面的内容,总结10条要点出来,\n{auido_txt}"
|
48 |
+
open_ai_res = create(prompt,openai_key)
|
49 |
answer = open_ai_res['choices'][0]['text']
|
50 |
|
51 |
res_content = f'音频内容:\n{auido_txt}\nGPT3总结的要点:\n{answer}'
|
|
|
64 |
print('aodio over ..')
|
65 |
return audio_file
|
66 |
|
67 |
+
def get_transcript(url,openai_key):
|
68 |
audio_file = get_audio(url)
|
69 |
# audio_file = 'tmp.mp4'
|
70 |
files = {
|
|
|
74 |
}
|
75 |
response = requests.post('https://api.gladia.io/audio/text/audio-transcription/', headers=headers, files=files)
|
76 |
print(response.text)
|
77 |
+
return convert(response,openai_key)
|
78 |
|
79 |
|
80 |
|
|
|
88 |
|
89 |
with gr.Row():
|
90 |
url = gr.Textbox(placeholder='Youtube video URL', label='URL')
|
91 |
+
openai_key = gr.Textbox(placeholder='Your openai key', label='key')
|
92 |
|
93 |
|
94 |
with gr.Row():
|
|
|
98 |
with gr.Column():
|
99 |
outputs = gr.Textbox(placeholder='Transcription of the video', label='Transcription')
|
100 |
|
101 |
+
transcribe_btn.click(get_transcript, inputs=[url,openai_key], outputs=outputs)
|
102 |
|
103 |
demo.launch(debug=True)
|