ginipick commited on
Commit
238c2d8
Β·
verified Β·
1 Parent(s): 560ab18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -10
app.py CHANGED
@@ -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, 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,10 +140,7 @@ def fetch_comments(video_url, system_prompt, reply_mode):
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,7 +165,7 @@ def fetch_comments(video_url, system_prompt, reply_mode):
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,9 +193,6 @@ with demo:
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,7 +202,7 @@ with demo:
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()
 
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
  if not new_comments or 'error' in new_comments[0]:
141
  return "λŒ“κΈ€μ„ 찾을 수 μ—†κ±°λ‚˜ 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€."
142
 
143
+ 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]
 
 
 
144
 
145
  if recent_new_comments:
146
  for most_recent_comment in recent_new_comments:
 
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
  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
  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()