Kims12 commited on
Commit
6faa7b9
Β·
verified Β·
1 Parent(s): 82bbb8a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -26
app.py CHANGED
@@ -279,10 +279,10 @@ def combined_analysis(blog_text: str, remove_freq1: bool, direct_keyword_input:
279
  def analysis_handler(blog_text: str, remove_freq1: bool, direct_keyword_input: str, direct_keyword_only: bool):
280
  debug_log("analysis_handler ν•¨μˆ˜ μ‹œμž‘")
281
  if direct_keyword_only:
282
- # 직접 ν‚€μ›Œλ“œ λΆ„μ„λ§Œ μˆ˜ν–‰
283
  return direct_keyword_analysis(blog_text, direct_keyword_input)
284
  else:
285
- # 톡합 뢄석 (ν˜•νƒœμ†Œ 뢄석 + 직접 ν‚€μ›Œλ“œ 뢄석)
286
  return combined_analysis(blog_text, remove_freq1, direct_keyword_input)
287
 
288
  # --- μŠ€ν¬λž˜ν•‘ μ‹€ν–‰ ---
@@ -292,39 +292,96 @@ def fetch_blog_content(url: str):
292
  debug_log("fetch_blog_content ν•¨μˆ˜ μ™„λ£Œ")
293
  return content
294
 
295
- # --- Gradio μΈν„°νŽ˜μ΄μŠ€ ꡬ성 ---
296
  custom_css = """
297
- .gradio-container { max-width: 960px; margin: auto; }
298
- .centered-button-row { justify-content: center; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  """
300
- with gr.Blocks(title="넀이버 λΈ”λ‘œκ·Έ ν˜•νƒœμ†Œ 뢄석 슀페이슀", css=custom_css) as demo:
301
- gr.Markdown("# 넀이버 λΈ”λ‘œκ·Έ ν˜•νƒœμ†Œ 뢄석 슀페이슀")
 
 
302
  # λΈ”λ‘œκ·Έ 링크와 μŠ€ν¬λž˜ν•‘ μ‹€ν–‰ λ²„νŠΌμ„ ν•œ κ·Έλ£Ή 내에 배치 (λ²„νŠΌμ€ κ°€μš΄λ° μ •λ ¬)
303
- with gr.Group():
304
- blog_url_input = gr.Textbox(label="넀이버 λΈ”λ‘œκ·Έ 링크", placeholder="예: https://blog.naver.com/ssboost/222983068507", lines=1)
305
- with gr.Row(elem_classes="centered-button-row"):
306
- scrape_button = gr.Button("μŠ€ν¬λž˜ν•‘ μ‹€ν–‰")
307
- with gr.Row():
 
308
  blog_content_box = gr.Textbox(label="λΈ”λ‘œκ·Έ λ‚΄μš© (μˆ˜μ • κ°€λŠ₯)", lines=10, placeholder="μŠ€ν¬λž˜ν•‘λœ λΈ”λ‘œκ·Έ λ‚΄μš©μ΄ 여기에 ν‘œμ‹œλ©λ‹ˆλ‹€.")
309
- with gr.Row():
310
- remove_freq_checkbox = gr.Checkbox(label="λΉˆλ„μˆ˜1 제거", value=True)
311
- # "λΉˆλ„μˆ˜1 제거" μ•„λž˜μ— "직접 ν‚€μ›Œλ“œ μž…λ ₯만 뢄석" 선택 ν•­λͺ© μΆ”κ°€ (κΈ°λ³Έ 미선택)
312
- with gr.Row():
313
- direct_keyword_only_checkbox = gr.Checkbox(label="직접 ν‚€μ›Œλ“œ μž…λ ₯만 뢄석", value=False)
314
- with gr.Row():
315
- direct_keyword_box = gr.Textbox(label="직접 ν‚€μ›Œλ“œ μž…λ ₯ (μ—”ν„° λ˜λŠ” ','둜 ꡬ뢄)", lines=2, placeholder="예: ν‚€μ›Œλ“œ1, ν‚€μ›Œλ“œ2\nν‚€μ›Œλ“œ3")
316
- with gr.Row():
317
- analyze_button = gr.Button("뢄석 μ‹€ν–‰")
318
- # κ²°κ³Ό ν…Œμ΄λΈ”μ€ ν™”λ©΄ 전체 폭을 μ‚¬μš©ν•˜κ³ , Excel λ‹€μš΄λ‘œλ“œ λ²„νŠΌμ€ κ·Έ μ•„λž˜ 별도 행에 배치
319
- with gr.Row():
 
320
  result_df = gr.Dataframe(label="톡합 뢄석 κ²°κ³Ό (단어, λΉˆλ„μˆ˜, κ²€μƒ‰λŸ‰, λΈ”λ‘œκ·Έλ¬Έμ„œμˆ˜, μ§μ ‘μž…λ ₯)", interactive=True)
321
- with gr.Row():
322
  excel_file = gr.File(label="Excel λ‹€μš΄λ‘œλ“œ")
323
 
324
  # 이벀트 μ—°κ²°
325
  scrape_button.click(fn=fetch_blog_content, inputs=blog_url_input, outputs=blog_content_box)
326
- analyze_button.click(fn=analysis_handler, inputs=[blog_content_box, remove_freq_checkbox, direct_keyword_box, direct_keyword_only_checkbox],
327
- outputs=[result_df, excel_file])
 
328
 
329
  if __name__ == "__main__":
330
  debug_log("Gradio μ•± μ‹€ν–‰ μ‹œμž‘")
 
279
  def analysis_handler(blog_text: str, remove_freq1: bool, direct_keyword_input: str, direct_keyword_only: bool):
280
  debug_log("analysis_handler ν•¨μˆ˜ μ‹œμž‘")
281
  if direct_keyword_only:
282
+ # "직접 ν‚€μ›Œλ“œ μž…λ ₯만 뢄석" 선택 μ‹œ 단독 뢄석 μˆ˜ν–‰
283
  return direct_keyword_analysis(blog_text, direct_keyword_input)
284
  else:
285
+ # κΈ°λ³Έ 톡합 뢄석 μˆ˜ν–‰
286
  return combined_analysis(blog_text, remove_freq1, direct_keyword_input)
287
 
288
  # --- μŠ€ν¬λž˜ν•‘ μ‹€ν–‰ ---
 
292
  debug_log("fetch_blog_content ν•¨μˆ˜ μ™„λ£Œ")
293
  return content
294
 
295
+ # --- Custom CSS ---
296
  custom_css = """
297
+ /* 전체 μ»¨ν…Œμ΄λ„ˆ μŠ€νƒ€μΌ */
298
+ .gradio-container {
299
+ max-width: 960px;
300
+ margin: auto;
301
+ font-family: 'Helvetica Neue', Arial, sans-serif;
302
+ background: #f5f7fa;
303
+ padding: 2rem;
304
+ }
305
+
306
+ /* 헀더 μŠ€νƒ€μΌ */
307
+ .custom-header {
308
+ text-align: center;
309
+ font-size: 2.5rem;
310
+ font-weight: bold;
311
+ margin-bottom: 1.5rem;
312
+ color: #333;
313
+ }
314
+
315
+ /* κ·Έλ£Ή λ°•μŠ€ μŠ€νƒ€μΌ */
316
+ .custom-group {
317
+ background: #ffffff;
318
+ border-radius: 8px;
319
+ padding: 1.5rem;
320
+ box-shadow: 0 2px 8px rgba(0,0,0,0.1);
321
+ margin-bottom: 1.5rem;
322
+ }
323
+
324
+ /* λ²„νŠΌ μŠ€νƒ€μΌ */
325
+ .custom-button {
326
+ background-color: #007bff;
327
+ color: #fff;
328
+ border: none;
329
+ border-radius: 4px;
330
+ padding: 0.6rem 1.2rem;
331
+ font-size: 1rem;
332
+ cursor: pointer;
333
+ }
334
+
335
+ /* μ²΄ν¬λ°•μŠ€ μŠ€νƒ€μΌ */
336
+ .custom-checkbox {
337
+ margin-right: 1rem;
338
+ }
339
+
340
+ /* κ²°κ³Ό ν…Œμ΄λΈ” 및 λ‹€μš΄λ‘œλ“œ λ²„νŠΌ */
341
+ .custom-result {
342
+ margin-top: 1.5rem;
343
+ }
344
+
345
+ /* κ°€μš΄λ° μ •λ ¬ */
346
+ .centered {
347
+ display: flex;
348
+ justify-content: center;
349
+ align-items: center;
350
+ }
351
  """
352
+
353
+ # --- Gradio μΈν„°νŽ˜μ΄μŠ€ ꡬ성 ---
354
+ with gr.Blocks(title="넀이버 λΈ”λ‘œκ·Έ ν˜•νƒœμ†Œ 뢄석 μ„œλΉ„μŠ€", css=custom_css) as demo:
355
+ gr.HTML("<div class='custom-header'>넀이버 λΈ”λ‘œκ·Έ ν˜•νƒœμ†Œ 뢄석 μ„œλΉ„μŠ€</div>")
356
  # λΈ”λ‘œκ·Έ 링크와 μŠ€ν¬λž˜ν•‘ μ‹€ν–‰ λ²„νŠΌμ„ ν•œ κ·Έλ£Ή 내에 배치 (λ²„νŠΌμ€ κ°€μš΄λ° μ •λ ¬)
357
+ with gr.Group(elem_classes="custom-group"):
358
+ with gr.Row():
359
+ blog_url_input = gr.Textbox(label="넀이버 λΈ”λ‘œκ·Έ 링크", placeholder="예: https://blog.naver.com/ssboost/222983068507", lines=1)
360
+ with gr.Row(elem_classes="centered"):
361
+ scrape_button = gr.Button("μŠ€ν¬λž˜ν•‘ μ‹€ν–‰", elem_classes="custom-button")
362
+ with gr.Group(elem_classes="custom-group"):
363
  blog_content_box = gr.Textbox(label="λΈ”λ‘œκ·Έ λ‚΄μš© (μˆ˜μ • κ°€λŠ₯)", lines=10, placeholder="μŠ€ν¬λž˜ν•‘λœ λΈ”λ‘œκ·Έ λ‚΄μš©μ΄ 여기에 ν‘œμ‹œλ©λ‹ˆλ‹€.")
364
+ with gr.Group(elem_classes="custom-group"):
365
+ with gr.Row():
366
+ remove_freq_checkbox = gr.Checkbox(label="λΉˆλ„μˆ˜1 제거", value=True, elem_classes="custom-checkbox")
367
+ with gr.Row():
368
+ # "λΉˆλ„μˆ˜1 제거" μ•„λž˜μ— "직접 ν‚€μ›Œλ“œ μž…λ ₯만 뢄석" μ²΄ν¬λ°•μŠ€ 배치
369
+ direct_keyword_only_checkbox = gr.Checkbox(label="직접 ν‚€μ›Œλ“œ μž…λ ₯만 뢄석", value=False, elem_classes="custom-checkbox")
370
+ with gr.Row():
371
+ direct_keyword_box = gr.Textbox(label="직접 ν‚€μ›Œλ“œ μž…λ ₯ (μ—”ν„° λ˜λŠ” ','둜 ꡬ뢄)", lines=2, placeholder="예: ν‚€μ›Œλ“œ1, ν‚€μ›Œλ“œ2\nν‚€μ›Œλ“œ3")
372
+ with gr.Group(elem_classes="custom-group"):
373
+ with gr.Row(elem_classes="centered"):
374
+ analyze_button = gr.Button("뢄석 μ‹€ν–‰", elem_classes="custom-button")
375
+ with gr.Group(elem_classes="custom-group custom-result"):
376
  result_df = gr.Dataframe(label="톡합 뢄석 κ²°κ³Ό (단어, λΉˆλ„μˆ˜, κ²€μƒ‰λŸ‰, λΈ”λ‘œκ·Έλ¬Έμ„œμˆ˜, μ§μ ‘μž…λ ₯)", interactive=True)
377
+ with gr.Group(elem_classes="custom-group"):
378
  excel_file = gr.File(label="Excel λ‹€μš΄λ‘œλ“œ")
379
 
380
  # 이벀트 μ—°κ²°
381
  scrape_button.click(fn=fetch_blog_content, inputs=blog_url_input, outputs=blog_content_box)
382
+ analyze_button.click(fn=analysis_handler,
383
+ inputs=[blog_content_box, remove_freq_checkbox, direct_keyword_box, direct_keyword_only_checkbox],
384
+ outputs=[result_df, excel_file])
385
 
386
  if __name__ == "__main__":
387
  debug_log("Gradio μ•± μ‹€ν–‰ μ‹œμž‘")