edchengg commited on
Commit
2446386
1 Parent(s): 1b12140

add instructions

Browse files
Files changed (1) hide show
  1. app.py +25 -8
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
  import openai
3
- import youtube_dl
4
  import os
5
  openai.api_key = os.environ['OPENAI_API_KEY']
6
 
@@ -8,11 +8,12 @@ def asr(url):
8
  # download audio
9
  # Options for youtube-dl
10
  ydl_opts = {
11
- 'outtmpl': 'my_video.mp4'
 
12
  }
13
 
14
  # Create a youtube-dl object
15
- ydl = youtube_dl.YoutubeDL(ydl_opts)
16
 
17
  # Download the video
18
  info_dict = ydl.extract_info(url, download=True)
@@ -25,12 +26,28 @@ def asr(url):
25
  {"role": "user", "content": "Transcript: {transcript}. \n Translate the video conversation transcript into fluent Chinese. Chinese: ".format(transcript=transcript["text"])},
26
  ]
27
  )
28
- return transcript["text"], output['choices'][0]['message']['content']
29
 
30
- demo = gr.Interface(fn=asr, inputs="text",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  outputs=[
32
- gr.outputs.Textbox(label="English"),
33
- gr.outputs.Textbox(label="Chinese"),
34
- ])
 
 
35
 
36
  demo.launch()
 
1
  import gradio as gr
2
  import openai
3
+ import yt_dlp
4
  import os
5
  openai.api_key = os.environ['OPENAI_API_KEY']
6
 
 
8
  # download audio
9
  # Options for youtube-dl
10
  ydl_opts = {
11
+ 'outtmpl': 'my_video.mp4',
12
+ 'overwrites': True,
13
  }
14
 
15
  # Create a youtube-dl object
16
+ ydl = yt_dlp.YoutubeDL(ydl_opts)
17
 
18
  # Download the video
19
  info_dict = ydl.extract_info(url, download=True)
 
26
  {"role": "user", "content": "Transcript: {transcript}. \n Translate the video conversation transcript into fluent Chinese. Chinese: ".format(transcript=transcript["text"])},
27
  ]
28
  )
29
+ return output['choices'][0]['message']['content'], transcript["text"]
30
 
31
+ title = """
32
+ 韬译云间"""
33
+ # Create an instruction input component
34
+ instruction = """
35
+ <div style="border: 2px solid #000; padding: 10px; border-radius: 5px;">
36
+ 一键输入视频链接,轻松实现中文翻译,畅享视频无障碍沟通 <span style="color: grey;">-- powered by OpenAI Whisper & ChatGPT.</span>.<br>
37
+
38
+ 1.将视频链接(支持Twitter、YouTube)复制粘贴至输入框,点击提交(Submit)即可;
39
+ 2.为保证翻译质量,目前仅支持处理时长不超过5分钟的短视频。
40
+ </div>"""
41
+ # Create a text input component
42
+ text_input = gr.inputs.Textbox()
43
+
44
+ demo = gr.Interface(fn=asr,
45
+ inputs=gr.inputs.Textbox(label="粘贴视频链接"),
46
  outputs=[
47
+ gr.outputs.Textbox(label="中文"),
48
+ gr.outputs.Textbox(label="英文"),
49
+ ],
50
+ title=title,
51
+ description=instruction)
52
 
53
  demo.launch()