Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,42 +2,60 @@ import os
|
|
2 |
os.system('pip uninstall vidfetch -y')
|
3 |
os.system('pip install -U https://github.com/dailingx/VidFetch/archive/master.zip')
|
4 |
os.system('pip install --upgrade google-api-python-client')
|
|
|
5 |
|
6 |
import sys
|
7 |
import gradio as gr
|
8 |
from vidfetch.website.youtube import YoutubeVideoDataset
|
|
|
|
|
9 |
|
10 |
|
11 |
def fetch(
|
12 |
-
|
13 |
dev_key: str,
|
14 |
hf_token: str,
|
15 |
-
hf_ds_repo_id: str
|
|
|
16 |
):
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
|
29 |
with gr.Blocks() as demo:
|
30 |
gr.Markdown('''OpenVideo Youtube fetch demo''')
|
31 |
with gr.Row():
|
32 |
with gr.Column():
|
33 |
-
kw_input_text = gr.Text(label='Keyword')
|
|
|
34 |
dev_key_input_text = gr.Text(label='Google Cloud Developer Key')
|
35 |
hf_token_input_text = gr.Text(label='HF Token')
|
36 |
hf_ds_repo_id_text = gr.Text(label='HF Dataset Repo ID, like: OpenVideo/YouTube-Commons-5G-Raw')
|
37 |
fetch_btn = gr.Button("Fetch")
|
38 |
result = gr.Text()
|
39 |
|
40 |
-
fetch_btn.click(fn=fetch, inputs=[
|
41 |
outputs=[result])
|
42 |
|
43 |
|
|
|
2 |
os.system('pip uninstall vidfetch -y')
|
3 |
os.system('pip install -U https://github.com/dailingx/VidFetch/archive/master.zip')
|
4 |
os.system('pip install --upgrade google-api-python-client')
|
5 |
+
os.system('pip install pandas')
|
6 |
|
7 |
import sys
|
8 |
import gradio as gr
|
9 |
from vidfetch.website.youtube import YoutubeVideoDataset
|
10 |
+
import pandas as pd
|
11 |
+
from pandas.api.types import is_numeric_dtype
|
12 |
|
13 |
|
14 |
def fetch(
|
15 |
+
kw_file,
|
16 |
dev_key: str,
|
17 |
hf_token: str,
|
18 |
+
hf_ds_repo_id: str,
|
19 |
+
key_word: str = None
|
20 |
):
|
21 |
+
df = pd.read_csv(kw_file.name)
|
22 |
+
if len(df['keyword']) <= 0:
|
23 |
+
return 'no keyword'
|
24 |
+
|
25 |
+
success_kw = ''
|
26 |
+
for index, value in df['keyword'].items():
|
27 |
+
if 'num' in df.columns:
|
28 |
+
video_max_num = df['num'][index]
|
29 |
+
else:
|
30 |
+
video_max_num = 1
|
31 |
+
|
32 |
+
youtube_video_dataset = YoutubeVideoDataset(
|
33 |
+
root_dir="./",
|
34 |
+
google_cloud_developer_key=dev_key,
|
35 |
+
search_keyword=value,
|
36 |
+
video_max_num=video_max_num,
|
37 |
+
hf_token=hf_token,
|
38 |
+
hf_ds_repo_id=hf_ds_repo_id
|
39 |
+
)
|
40 |
+
youtube_video_dataset.download()
|
41 |
+
|
42 |
+
success_kw = success_kw + value
|
43 |
+
return success_kw
|
44 |
|
45 |
|
46 |
with gr.Blocks() as demo:
|
47 |
gr.Markdown('''OpenVideo Youtube fetch demo''')
|
48 |
with gr.Row():
|
49 |
with gr.Column():
|
50 |
+
# kw_input_text = gr.Text(label='Keyword')
|
51 |
+
kw_input_file = gr.File(label="Upload CSV File, Include Columns: keyword, num, ...")
|
52 |
dev_key_input_text = gr.Text(label='Google Cloud Developer Key')
|
53 |
hf_token_input_text = gr.Text(label='HF Token')
|
54 |
hf_ds_repo_id_text = gr.Text(label='HF Dataset Repo ID, like: OpenVideo/YouTube-Commons-5G-Raw')
|
55 |
fetch_btn = gr.Button("Fetch")
|
56 |
result = gr.Text()
|
57 |
|
58 |
+
fetch_btn.click(fn=fetch, inputs=[kw_input_file, dev_key_input_text, hf_token_input_text, hf_ds_repo_id_text],
|
59 |
outputs=[result])
|
60 |
|
61 |
|