Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,57 @@
|
|
1 |
import gradio as gr
|
2 |
from googleapiclient.discovery import build
|
3 |
from google_auth_oauthlib.flow import InstalledAppFlow
|
4 |
-
from google.oauth2.credentials import Credentials
|
5 |
-
import os
|
6 |
|
7 |
-
# YouTube API
|
8 |
-
|
9 |
-
|
10 |
-
def update_video_descriptions(additional_text):
|
11 |
-
creds = None
|
12 |
-
# ์ธ์ฆ ํ๋ก์ธ์ค
|
13 |
-
flow = InstalledAppFlow.from_client_secrets_file(
|
14 |
-
os.environ['CLIENT_SECRETS_FILE'], SCOPES)
|
15 |
creds = flow.run_local_server(port=0)
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
|
|
|
|
20 |
response = request.execute()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
return update_video_descriptions(text)
|
38 |
|
39 |
-
interface = gr.Interface(fn=add_text_to_videos, inputs="text", outputs="text", title="Update YouTube Video Descriptions")
|
40 |
-
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from googleapiclient.discovery import build
|
3 |
from google_auth_oauthlib.flow import InstalledAppFlow
|
|
|
|
|
4 |
|
5 |
+
# YouTube API ์ธ์ฆ ๋ฐ ํด๋ผ์ด์ธํธ ์ด๊ธฐํ
|
6 |
+
def authenticate_youtube():
|
7 |
+
flow = InstalledAppFlow.from_client_secrets_file('client_secrets.json', ['https://www.googleapis.com/auth/youtube.force-ssl'])
|
|
|
|
|
|
|
|
|
|
|
8 |
creds = flow.run_local_server(port=0)
|
9 |
+
return build('youtube', 'v3', credentials=creds)
|
10 |
+
|
11 |
+
# ํ์ฌ ๋์์ ์ค๋ช
๊ฐ์ ธ์ค๊ธฐ
|
12 |
+
def get_video_description(video_id):
|
13 |
+
youtube = authenticate_youtube()
|
14 |
+
request = youtube.videos().list(part='snippet', id=video_id)
|
15 |
+
response = request.execute()
|
16 |
+
|
17 |
+
if not response['items']:
|
18 |
+
return 'Video not found.'
|
19 |
+
|
20 |
+
video = response['items'][0]
|
21 |
+
snippet = video['snippet']
|
22 |
+
|
23 |
+
return snippet['description']
|
24 |
|
25 |
+
# ๋์์ ์ค๋ช
์
๋ฐ์ดํธ
|
26 |
+
def update_video_description(video_id, additional_text):
|
27 |
+
youtube = authenticate_youtube()
|
28 |
+
request = youtube.videos().list(part='snippet', id=video_id)
|
29 |
response = request.execute()
|
30 |
+
|
31 |
+
if not response['items']:
|
32 |
+
return 'Video not found.'
|
33 |
+
|
34 |
+
video = response['items'][0]
|
35 |
+
snippet = video['snippet']
|
36 |
+
snippet['description'] += f"\n\n{additional_text}"
|
37 |
+
|
38 |
+
youtube.videos().update(part='snippet', body={'id': video_id, 'snippet': snippet}).execute()
|
39 |
+
|
40 |
+
return 'Successfully updated the video description.'
|
41 |
|
42 |
+
# Gradio ์ธํฐํ์ด์ค ์ค์
|
43 |
+
with gr.Blocks() as app:
|
44 |
+
gr.Markdown("YouTube Video Description Manager")
|
45 |
+
with gr.Row():
|
46 |
+
video_id_input = gr.Textbox(label="Video ID")
|
47 |
+
get_desc_button = gr.Button("Get Description")
|
48 |
+
description_output = gr.Textbox(label="Current Description", lines=4, interactive=False)
|
49 |
+
additional_text_input = gr.Textbox(label="Additional Text to Add", lines=4)
|
50 |
+
update_button = gr.Button("Update Description")
|
51 |
+
result_output = gr.Textbox(label="Result", interactive=False)
|
52 |
+
|
53 |
+
get_desc_button.click(fn=get_video_description, inputs=video_id_input, outputs=description_output)
|
54 |
+
update_button.click(fn=update_video_description, inputs=[video_id_input, additional_text_input], outputs=result_output)
|
55 |
|
56 |
+
app.launch()
|
|
|
57 |
|
|
|
|