Merge branch 'main' of https://huggingface.co/spaces/ychenNLP/just4fun
Browse files- demo_gradio.py +0 -35
demo_gradio.py
DELETED
@@ -1,35 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import openai
|
3 |
-
import youtube_dl
|
4 |
-
|
5 |
-
|
6 |
-
def asr(url):
|
7 |
-
# download audio
|
8 |
-
# Options for youtube-dl
|
9 |
-
ydl_opts = {
|
10 |
-
'outtmpl': 'my_video.mp4'
|
11 |
-
}
|
12 |
-
|
13 |
-
# Create a youtube-dl object
|
14 |
-
ydl = youtube_dl.YoutubeDL(ydl_opts)
|
15 |
-
|
16 |
-
# Download the video
|
17 |
-
info_dict = ydl.extract_info(url, download=True)
|
18 |
-
|
19 |
-
audio_file= open("my_video.mp4", "rb")
|
20 |
-
transcript = openai.Audio.transcribe("whisper-1", audio_file)
|
21 |
-
output = openai.ChatCompletion.create(
|
22 |
-
model="gpt-3.5-turbo",
|
23 |
-
messages=[
|
24 |
-
{"role": "user", "content": "Transcript: {transcript}. \n Translate the video conversation transcript into fluent Chinese. Chinese: ".format(transcript=transcript["text"])},
|
25 |
-
]
|
26 |
-
)
|
27 |
-
return transcript["text"], output['choices'][0]['message']['content']
|
28 |
-
|
29 |
-
demo = gr.Interface(fn=asr, inputs="text",
|
30 |
-
outputs=[
|
31 |
-
gr.outputs.Textbox(label="English"),
|
32 |
-
gr.outputs.Textbox(label="Chinese"),
|
33 |
-
])
|
34 |
-
|
35 |
-
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|