Update app.py
Browse files
app.py
CHANGED
@@ -93,7 +93,7 @@ def get_video_comments(video_id):
|
|
93 |
request = youtube.commentThreads().list(
|
94 |
part='snippet',
|
95 |
videoId=video_id,
|
96 |
-
maxResults=
|
97 |
textFormat='plainText'
|
98 |
)
|
99 |
response = request.execute()
|
@@ -113,7 +113,7 @@ def get_video_comments(video_id):
|
|
113 |
part='snippet',
|
114 |
videoId=video_id,
|
115 |
pageToken=response['nextPageToken'],
|
116 |
-
maxResults=
|
117 |
textFormat='plainText'
|
118 |
)
|
119 |
response = request.execute()
|
@@ -123,7 +123,7 @@ def get_video_comments(video_id):
|
|
123 |
except Exception as e:
|
124 |
return [{'error': str(e)}]
|
125 |
|
126 |
-
def fetch_comments(video_url, system_prompt):
|
127 |
log_entries = []
|
128 |
video_id_match = re.search(r'(?:v=|\/)([0-9A-Za-z_-]{11}).*', video_url)
|
129 |
if video_id_match:
|
@@ -140,7 +140,10 @@ def fetch_comments(video_url, system_prompt):
|
|
140 |
if not new_comments or 'error' in new_comments[0]:
|
141 |
return "λκΈμ μ°Ύμ μ μκ±°λ μ€λ₯κ° λ°μνμ΅λλ€."
|
142 |
|
143 |
-
|
|
|
|
|
|
|
144 |
|
145 |
if recent_new_comments:
|
146 |
for most_recent_comment in recent_new_comments:
|
@@ -165,7 +168,7 @@ def fetch_comments(video_url, system_prompt):
|
|
165 |
|
166 |
def background_fetch_comments():
|
167 |
while not stop_event.is_set():
|
168 |
-
result = fetch_comments("https://www.youtube.com/watch?v=dQw4w9WgXcQ", DEFAULT_SYSTEM_PROMPT) # URLκ³Ό ν둬ννΈ μ€μ μ¬μ© μμ
|
169 |
print(result)
|
170 |
time.sleep(10)
|
171 |
|
@@ -193,6 +196,9 @@ with demo:
|
|
193 |
input_text_url = gr.Textbox(placeholder='YouTube video URL', label='YouTube URL')
|
194 |
input_text_prompt = gr.Textbox(placeholder='μμ€ν
ν둬ννΈ', label='μμ€ν
ν둬ννΈ', value=DEFAULT_SYSTEM_PROMPT, lines=5)
|
195 |
|
|
|
|
|
|
|
196 |
with gr.Row():
|
197 |
result_button_transcribe = gr.Button('Transcribe')
|
198 |
result_button_comments = gr.Button('Fetch Comments and Generate Reply')
|
@@ -202,7 +208,7 @@ with demo:
|
|
202 |
output_text_prompt = gr.Textbox(placeholder='μλ΅ ν
μ€νΈ', label='μλ΅ ν
μ€νΈ', lines=20)
|
203 |
|
204 |
result_button_transcribe.click(get_text, inputs=input_text_url, outputs=output_text_transcribe, api_name="transcribe_api")
|
205 |
-
result_button_comments.click(fetch_comments, inputs=[input_text_url, input_text_prompt], outputs=output_text_prompt, api_name="fetch_comments_api")
|
206 |
|
207 |
# μΈν°νμ΄μ€ μ€ν
|
208 |
demo.launch()
|
|
|
93 |
request = youtube.commentThreads().list(
|
94 |
part='snippet',
|
95 |
videoId=video_id,
|
96 |
+
maxResults=10, #λκΈ μ½μ΄λ€μ΄λ μ μ μ
|
97 |
textFormat='plainText'
|
98 |
)
|
99 |
response = request.execute()
|
|
|
113 |
part='snippet',
|
114 |
videoId=video_id,
|
115 |
pageToken=response['nextPageToken'],
|
116 |
+
maxResults=10, #λκΈ μ½μ΄λ€μ΄λ μ μ μ
|
117 |
textFormat='plainText'
|
118 |
)
|
119 |
response = request.execute()
|
|
|
123 |
except Exception as e:
|
124 |
return [{'error': str(e)}]
|
125 |
|
126 |
+
def fetch_comments(video_url, system_prompt, reply_mode):
|
127 |
log_entries = []
|
128 |
video_id_match = re.search(r'(?:v=|\/)([0-9A-Za-z_-]{11}).*', video_url)
|
129 |
if video_id_match:
|
|
|
140 |
if not new_comments or 'error' in new_comments[0]:
|
141 |
return "λκΈμ μ°Ύμ μ μκ±°λ μ€λ₯κ° λ°μνμ΅λλ€."
|
142 |
|
143 |
+
if reply_mode == "Non Reply":
|
144 |
+
recent_new_comments = [c for c in new_comments if c['comment_id'] not in {c['comment_id'] for c in existing_comments} and c['reply_count'] == 0]
|
145 |
+
else:
|
146 |
+
recent_new_comments = [c for c in new_comments if c['comment_id'] not in {c['comment_id'] for c in existing_comments}]
|
147 |
|
148 |
if recent_new_comments:
|
149 |
for most_recent_comment in recent_new_comments:
|
|
|
168 |
|
169 |
def background_fetch_comments():
|
170 |
while not stop_event.is_set():
|
171 |
+
result = fetch_comments("https://www.youtube.com/watch?v=dQw4w9WgXcQ", DEFAULT_SYSTEM_PROMPT, "Non Reply") # URLκ³Ό ν둬ννΈ μ€μ μ¬μ© μμ
|
172 |
print(result)
|
173 |
time.sleep(10)
|
174 |
|
|
|
196 |
input_text_url = gr.Textbox(placeholder='YouTube video URL', label='YouTube URL')
|
197 |
input_text_prompt = gr.Textbox(placeholder='μμ€ν
ν둬ννΈ', label='μμ€ν
ν둬ννΈ', value=DEFAULT_SYSTEM_PROMPT, lines=5)
|
198 |
|
199 |
+
with gr.Row():
|
200 |
+
radio_reply_mode = gr.Radio(['Non Reply', 'Force Reply'], label='Reply Mode', value='Non Reply')
|
201 |
+
|
202 |
with gr.Row():
|
203 |
result_button_transcribe = gr.Button('Transcribe')
|
204 |
result_button_comments = gr.Button('Fetch Comments and Generate Reply')
|
|
|
208 |
output_text_prompt = gr.Textbox(placeholder='μλ΅ ν
μ€νΈ', label='μλ΅ ν
μ€νΈ', lines=20)
|
209 |
|
210 |
result_button_transcribe.click(get_text, inputs=input_text_url, outputs=output_text_transcribe, api_name="transcribe_api")
|
211 |
+
result_button_comments.click(fetch_comments, inputs=[input_text_url, input_text_prompt, radio_reply_mode], outputs=output_text_prompt, api_name="fetch_comments_api")
|
212 |
|
213 |
# μΈν°νμ΄μ€ μ€ν
|
214 |
demo.launch()
|