Spaces:
Sleeping
Sleeping
v5
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import gradio as gr
|
|
3 |
from pytube import YouTube
|
4 |
|
5 |
|
6 |
-
import requests
|
7 |
|
8 |
headers = {
|
9 |
'accept': 'application/json',
|
@@ -13,13 +13,47 @@ headers = {
|
|
13 |
}
|
14 |
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
def convert(res):
|
17 |
data = res.json()
|
18 |
prediction = data['prediction']
|
19 |
content = []
|
20 |
for x in prediction:
|
21 |
content.append(x['transcription'])
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
|
25 |
def get_audio(url):
|
|
|
3 |
from pytube import YouTube
|
4 |
|
5 |
|
6 |
+
import requests,json
|
7 |
|
8 |
headers = {
|
9 |
'accept': 'application/json',
|
|
|
13 |
}
|
14 |
|
15 |
|
16 |
+
openai_key = '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'
|
17 |
+
|
18 |
+
headers = {
|
19 |
+
'Content-Type': 'application/json',
|
20 |
+
'Authorization': f'Bearer {openai_key}',
|
21 |
+
|
22 |
+
}
|
23 |
+
|
24 |
+
def create(prompt):
|
25 |
+
data = {
|
26 |
+
"model": "text-davinci-003",
|
27 |
+
"prompt": prompt,
|
28 |
+
"temperature": 0.7,
|
29 |
+
"max_tokens": 1024,
|
30 |
+
"top_p": 1.0,
|
31 |
+
"frequency_penalty": 0.0,
|
32 |
+
"presence_penalty": 0.0
|
33 |
+
}
|
34 |
+
url = 'https://api.openai.com/v1/completions'
|
35 |
+
r = requests.post(url,headers=headers,
|
36 |
+
data=json.dumps(data))
|
37 |
+
return r.json()
|
38 |
+
|
39 |
+
|
40 |
def convert(res):
|
41 |
data = res.json()
|
42 |
prediction = data['prediction']
|
43 |
content = []
|
44 |
for x in prediction:
|
45 |
content.append(x['transcription'])
|
46 |
+
auido_txt = '\n'.join(content)
|
47 |
+
|
48 |
+
prompt = f"将下面的内容,总结10条要点出来,\n{auido_txt}"
|
49 |
+
open_ai_res = create(prompt)
|
50 |
+
answer = open_ai_res['choices'][0]['text']
|
51 |
+
|
52 |
+
res_content = f'音频内容:\n{auido_txt}\nGPT3总结的要点:\n{answer}'
|
53 |
+
|
54 |
+
return res_content
|
55 |
+
|
56 |
+
|
57 |
|
58 |
|
59 |
def get_audio(url):
|