Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,62 @@
|
|
1 |
import gradio as gr
|
2 |
from textblob import TextBlob
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
Analyze the sentiment of the given text.
|
7 |
|
|
|
|
|
8 |
Args:
|
9 |
-
|
10 |
-
|
11 |
Returns:
|
12 |
-
|
|
|
13 |
"""
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
}
|
|
|
|
|
|
|
|
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
# Create the Gradio interface
|
24 |
demo = gr.Interface(
|
25 |
-
fn=
|
26 |
-
inputs=gr.Textbox(placeholder="Enter
|
27 |
outputs=gr.JSON(),
|
28 |
-
title="
|
29 |
-
description="
|
30 |
)
|
31 |
|
32 |
# Launch the interface and MCP server
|
33 |
if __name__ == "__main__":
|
34 |
-
demo.launch(
|
|
|
1 |
import gradio as gr
|
2 |
from textblob import TextBlob
|
3 |
|
4 |
+
import yt_dlp
|
5 |
+
import os
|
|
|
6 |
|
7 |
+
def download_video(url, request):
|
8 |
+
"""downlad video and audio from youtube url
|
9 |
Args:
|
10 |
+
url (str): youtube video url
|
11 |
+
output_path (str): path to save the downloaded files
|
12 |
Returns:
|
13 |
+
video_filename (str): path to the downloaded video file
|
14 |
+
audio_filename (str): path to the downloaded audio file
|
15 |
"""
|
16 |
+
|
17 |
+
# instanciate output path
|
18 |
+
output_path='./cache'
|
19 |
+
if not os.path.exists(output_path):
|
20 |
+
os.mkdir(output_path)
|
21 |
+
|
22 |
+
# get video
|
23 |
+
ydl_opts_video = {
|
24 |
+
'format': 'worst[ext=mp4]',
|
25 |
+
'outtmpl': output_path+'/video/'+'%(title)s_video.%(ext)s',
|
26 |
+
'quiet': True
|
27 |
}
|
28 |
+
print('Downloading video...')
|
29 |
+
with yt_dlp.YoutubeDL(ydl_opts_video) as ydl:
|
30 |
+
info_dict = ydl.extract_info(url, download=True)
|
31 |
+
video_filename = ydl.prepare_filename(info_dict)
|
32 |
|
33 |
+
# get audio
|
34 |
+
audio_opts = {
|
35 |
+
'format': 'bestaudio[ext=m4a]',
|
36 |
+
'outtmpl': output_path+'/audio/'+'%(title)s.audio.%(ext)s',
|
37 |
+
'quiet': False,
|
38 |
+
'noplaylist': True,
|
39 |
+
}
|
40 |
+
print('Downloading audio...')
|
41 |
+
with yt_dlp.YoutubeDL(audio_opts) as ydl:
|
42 |
+
info_dict = ydl.extract_info(url, download=True)
|
43 |
+
audio_filename = ydl.prepare_filename(info_dict)
|
44 |
+
|
45 |
+
|
46 |
+
return {
|
47 |
+
"video_path": video_filename,
|
48 |
+
"audio_path": audio_filename,
|
49 |
+
"request": request
|
50 |
+
}
|
51 |
# Create the Gradio interface
|
52 |
demo = gr.Interface(
|
53 |
+
fn=download_video, # will use function arguments to define inputs names
|
54 |
+
inputs=[gr.Textbox(placeholder="Enter video url"),gr.Textbox(placeholder="Enter request")],
|
55 |
outputs=gr.JSON(),
|
56 |
+
title="Video information request",
|
57 |
+
description="Retreive user's request information from a video"
|
58 |
)
|
59 |
|
60 |
# Launch the interface and MCP server
|
61 |
if __name__ == "__main__":
|
62 |
+
demo.launch()
|