Update app.py
Browse files
app.py
CHANGED
@@ -311,7 +311,7 @@ def serphouse_search(query, country):
|
|
311 |
return format_results_from_raw(response_data)
|
312 |
|
313 |
|
314 |
-
# Hacker News API ๊ด๋ จ
|
315 |
def get_hn_item(item_id):
|
316 |
"""๊ฐ๋ณ ์์ดํ
์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ"""
|
317 |
try:
|
@@ -323,11 +323,9 @@ def get_hn_item(item_id):
|
|
323 |
def get_recent_stories():
|
324 |
"""์ต์ ์คํ ๋ฆฌ ๊ฐ์ ธ์ค๊ธฐ"""
|
325 |
try:
|
326 |
-
# newstories ์๋ํฌ์ธํธ๋ก ์ต์ ์คํ ๋ฆฌ ID ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ
|
327 |
response = requests.get("https://hacker-news.firebaseio.com/v0/newstories.json")
|
328 |
story_ids = response.json()
|
329 |
|
330 |
-
# 24์๊ฐ ์ด๋ด ์คํ ๋ฆฌ๋ง ํํฐ๋ง
|
331 |
recent_stories = []
|
332 |
current_time = datetime.now().timestamp()
|
333 |
day_ago = current_time - (24 * 60 * 60)
|
@@ -337,8 +335,7 @@ def get_recent_stories():
|
|
337 |
if story and 'time' in story and story['time'] > day_ago:
|
338 |
recent_stories.append(story)
|
339 |
|
340 |
-
|
341 |
-
if len(recent_stories) >= 100: # ์ต๋ 100๊ฐ๋ก ์ ํ
|
342 |
break
|
343 |
|
344 |
return recent_stories
|
@@ -354,6 +351,43 @@ def format_hn_time(timestamp):
|
|
354 |
except:
|
355 |
return "Unknown time"
|
356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
|
358 |
css = """
|
359 |
footer {visibility: hidden;}
|
@@ -457,12 +491,12 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
457 |
'index': i,
|
458 |
})
|
459 |
|
|
|
460 |
with gr.Tab("์ ์ธ๊ณ"):
|
461 |
gr.Markdown("๊ฒ์์ด๋ฅผ ์
๋ ฅํ๋ฉด 67๊ฐ๊ตญ(ํ๊ตญ ์ ์ธ) ์ ์ฒด์ ๋ํด ๊ตญ๊ฐ๋ณ๋ก ๊ตฌ๋ถํ์ฌ 24์๊ฐ ์ด๋ด ๋ด์ค๊ฐ ์ต๋ 1000๊ฐ ์์ฐจ ์ถ๋ ฅ๋ฉ๋๋ค.")
|
462 |
gr.Markdown("๊ตญ๊ฐ ์ ํํ ๊ฒ์์ด์ 'ํ๊ธ'์ ์
๋ ฅํ๋ฉด ํ์ง ์ธ์ด๋ก ๋ฒ์ญ๋์ด ๊ฒ์ํฉ๋๋ค. ์: 'Taiwan' ๊ตญ๊ฐ ์ ํํ '์ผ์ฑ' ์
๋ ฅ์ 'ไธๆ'์ผ๋ก ์๋ ๊ฒ์")
|
463 |
|
464 |
with gr.Column():
|
465 |
-
# ์๋จ ์์ญ
|
466 |
with gr.Column(elem_id="status_area"):
|
467 |
with gr.Row():
|
468 |
query_global = gr.Textbox(label="๊ฒ์์ด")
|
@@ -471,7 +505,6 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
471 |
status_message_global = gr.Markdown("")
|
472 |
translated_query_display_global = gr.Markdown("")
|
473 |
|
474 |
-
# ๊ฒฐ๊ณผ ์ถ๋ ฅ ์์ญ
|
475 |
with gr.Column(elem_id="results_area"):
|
476 |
articles_state_global = gr.State([])
|
477 |
|
@@ -492,6 +525,37 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
492 |
'index': i,
|
493 |
})
|
494 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
495 |
def search_and_display(query, country, articles_state, progress=gr.Progress()):
|
496 |
status_msg = "๊ฒ์์ ์งํ์ค์
๋๋ค. ์ ์๋ง ๊ธฐ๋ค๋ฆฌ์ธ์..."
|
497 |
|
@@ -627,6 +691,12 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
627 |
outputs[0] = gr.update(value=final_status, visible=True)
|
628 |
yield outputs
|
629 |
|
|
|
|
|
|
|
|
|
|
|
|
|
630 |
search_outputs = [
|
631 |
status_message,
|
632 |
translated_query_display,
|
@@ -647,6 +717,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
647 |
show_progress=True
|
648 |
)
|
649 |
|
|
|
650 |
global_search_outputs = [
|
651 |
status_message_global,
|
652 |
translated_query_display_global,
|
@@ -665,80 +736,18 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css, title="NewsAI ์๋น์ค") as
|
|
665 |
outputs=global_search_outputs
|
666 |
)
|
667 |
|
668 |
-
#
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
# ๊ฒฐ๊ณผ ์ถ๋ ฅ ์์ญ
|
677 |
-
with gr.Column(elem_id="hn_results_area"):
|
678 |
-
hn_articles_state = gr.State([])
|
679 |
-
|
680 |
-
hn_article_components = []
|
681 |
-
for i in range(100): # ์ต๋ 100๊ฐ ํ์
|
682 |
-
with gr.Group(visible=False) as article_group:
|
683 |
-
title = gr.Markdown()
|
684 |
-
info = gr.Markdown()
|
685 |
-
|
686 |
-
hn_article_components.append({
|
687 |
-
'group': article_group,
|
688 |
-
'title': title,
|
689 |
-
'info': info,
|
690 |
-
'index': i,
|
691 |
-
})
|
692 |
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
outputs = [gr.update(value=status_msg, visible=True)]
|
698 |
-
|
699 |
-
# ๋ชจ๋ ์ปดํฌ๋ํธ ์ด๊ธฐํ
|
700 |
-
for _ in hn_article_components:
|
701 |
-
outputs.extend([
|
702 |
-
gr.update(visible=False),
|
703 |
-
gr.update(),
|
704 |
-
gr.update()
|
705 |
-
])
|
706 |
-
|
707 |
-
# ์ต์ ์คํ ๋ฆฌ ๊ฐ์ ธ์ค๊ธฐ
|
708 |
-
stories = get_recent_stories()
|
709 |
-
|
710 |
-
# ๊ฒฐ๊ณผ ์
๋ฐ์ดํธ
|
711 |
-
outputs = [gr.update(value=f"์ด {len(stories)}๊ฐ์ ํฌ์คํธ๋ฅผ ์ฐพ์์ต๋๋ค.", visible=True)]
|
712 |
-
|
713 |
-
for idx, comp in enumerate(hn_article_components):
|
714 |
-
if idx < len(stories):
|
715 |
-
story = stories[idx]
|
716 |
-
outputs.extend([
|
717 |
-
gr.update(visible=True),
|
718 |
-
gr.update(value=f"### [{story.get('title', 'Untitled')}]({story.get('url', '#')})"),
|
719 |
-
gr.update(value=f"**์์ฑ์:** {story.get('by', 'unknown')} | **์๊ฐ:** {format_hn_time(story.get('time', 0))} | **์ ์:** {story.get('score', 0)} | **๋๊ธ:** {len(story.get('kids', []))}๊ฐ")
|
720 |
-
])
|
721 |
-
else:
|
722 |
-
outputs.extend([
|
723 |
-
gr.update(visible=False),
|
724 |
-
gr.update(),
|
725 |
-
gr.update()
|
726 |
-
])
|
727 |
-
|
728 |
-
return outputs
|
729 |
-
|
730 |
-
# ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
731 |
-
hn_outputs = [status_message_hn]
|
732 |
-
for comp in hn_article_components:
|
733 |
-
hn_outputs.extend([
|
734 |
-
comp['group'],
|
735 |
-
comp['title'],
|
736 |
-
comp['info']
|
737 |
-
])
|
738 |
-
|
739 |
-
refresh_button.click(
|
740 |
-
refresh_hn_stories,
|
741 |
-
outputs=hn_outputs
|
742 |
-
)
|
743 |
|
744 |
iface.launch(auth=("it1","chosun1"))
|
|
|
311 |
return format_results_from_raw(response_data)
|
312 |
|
313 |
|
314 |
+
# Hacker News API ๊ด๋ จ ํจ์๋ค ๋จผ์ ์ถ๊ฐ
|
315 |
def get_hn_item(item_id):
|
316 |
"""๊ฐ๋ณ ์์ดํ
์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ"""
|
317 |
try:
|
|
|
323 |
def get_recent_stories():
|
324 |
"""์ต์ ์คํ ๋ฆฌ ๊ฐ์ ธ์ค๊ธฐ"""
|
325 |
try:
|
|
|
326 |
response = requests.get("https://hacker-news.firebaseio.com/v0/newstories.json")
|
327 |
story_ids = response.json()
|
328 |
|
|
|
329 |
recent_stories = []
|
330 |
current_time = datetime.now().timestamp()
|
331 |
day_ago = current_time - (24 * 60 * 60)
|
|
|
335 |
if story and 'time' in story and story['time'] > day_ago:
|
336 |
recent_stories.append(story)
|
337 |
|
338 |
+
if len(recent_stories) >= 100:
|
|
|
339 |
break
|
340 |
|
341 |
return recent_stories
|
|
|
351 |
except:
|
352 |
return "Unknown time"
|
353 |
|
354 |
+
def refresh_hn_stories():
|
355 |
+
"""Hacker News ์คํ ๋ฆฌ ์๋ก๊ณ ์นจ"""
|
356 |
+
status_msg = "Hacker News ํฌ์คํธ๋ฅผ ๊ฐ์ ธ์ค๋ ์ค..."
|
357 |
+
|
358 |
+
outputs = [gr.update(value=status_msg, visible=True)]
|
359 |
+
|
360 |
+
# ๋ชจ๋ ์ปดํฌ๋ํธ ์ด๊ธฐํ
|
361 |
+
for _ in hn_article_components:
|
362 |
+
outputs.extend([
|
363 |
+
gr.update(visible=False),
|
364 |
+
gr.update(),
|
365 |
+
gr.update()
|
366 |
+
])
|
367 |
+
|
368 |
+
# ์ต์ ์คํ ๋ฆฌ ๊ฐ์ ธ์ค๊ธฐ
|
369 |
+
stories = get_recent_stories()
|
370 |
+
|
371 |
+
# ๊ฒฐ๊ณผ ์
๋ฐ์ดํธ
|
372 |
+
outputs = [gr.update(value=f"์ด {len(stories)}๊ฐ์ ํฌ์คํธ๋ฅผ ์ฐพ์์ต๋๋ค.", visible=True)]
|
373 |
+
|
374 |
+
for idx, comp in enumerate(hn_article_components):
|
375 |
+
if idx < len(stories):
|
376 |
+
story = stories[idx]
|
377 |
+
outputs.extend([
|
378 |
+
gr.update(visible=True),
|
379 |
+
gr.update(value=f"### [{story.get('title', 'Untitled')}]({story.get('url', '#')})"),
|
380 |
+
gr.update(value=f"**์์ฑ์:** {story.get('by', 'unknown')} | **์๊ฐ:** {format_hn_time(story.get('time', 0))} | **์ ์:** {story.get('score', 0)} | **๋๊ธ:** {len(story.get('kids', []))}๊ฐ")
|
381 |
+
])
|
382 |
+
else:
|
383 |
+
outputs.extend([
|
384 |
+
gr.update(visible=False),
|
385 |
+
gr.update(),
|
386 |
+
gr.update()
|
387 |
+
])
|
388 |
+
|
389 |
+
return outputs
|
390 |
+
|
391 |
|
392 |
css = """
|
393 |
footer {visibility: hidden;}
|
|
|
491 |
'index': i,
|
492 |
})
|
493 |
|
494 |
+
# ์ ์ธ๊ณ ํญ
|
495 |
with gr.Tab("์ ์ธ๊ณ"):
|
496 |
gr.Markdown("๊ฒ์์ด๋ฅผ ์
๋ ฅํ๋ฉด 67๊ฐ๊ตญ(ํ๊ตญ ์ ์ธ) ์ ์ฒด์ ๋ํด ๊ตญ๊ฐ๋ณ๋ก ๊ตฌ๋ถํ์ฌ 24์๊ฐ ์ด๋ด ๋ด์ค๊ฐ ์ต๋ 1000๊ฐ ์์ฐจ ์ถ๋ ฅ๋ฉ๋๋ค.")
|
497 |
gr.Markdown("๊ตญ๊ฐ ์ ํํ ๊ฒ์์ด์ 'ํ๊ธ'์ ์
๋ ฅํ๋ฉด ํ์ง ์ธ์ด๋ก ๋ฒ์ญ๋์ด ๊ฒ์ํฉ๋๋ค. ์: 'Taiwan' ๊ตญ๊ฐ ์ ํํ '์ผ์ฑ' ์
๋ ฅ์ 'ไธๆ'์ผ๋ก ์๋ ๊ฒ์")
|
498 |
|
499 |
with gr.Column():
|
|
|
500 |
with gr.Column(elem_id="status_area"):
|
501 |
with gr.Row():
|
502 |
query_global = gr.Textbox(label="๊ฒ์์ด")
|
|
|
505 |
status_message_global = gr.Markdown("")
|
506 |
translated_query_display_global = gr.Markdown("")
|
507 |
|
|
|
508 |
with gr.Column(elem_id="results_area"):
|
509 |
articles_state_global = gr.State([])
|
510 |
|
|
|
525 |
'index': i,
|
526 |
})
|
527 |
|
528 |
+
# AI ๋ฆฌํฌํฐ ํญ
|
529 |
+
with gr.Tab("AI ๋ฆฌํฌํฐ"):
|
530 |
+
gr.Markdown("์ง๋ 24์๊ฐ ๋์์ Hacker News ํฌ์คํธ๋ฅผ ๋ณด์ฌ์ค๋๋ค.")
|
531 |
+
|
532 |
+
with gr.Column():
|
533 |
+
refresh_button = gr.Button("์๋ก๊ณ ์นจ", variant="primary")
|
534 |
+
status_message_hn = gr.Markdown("")
|
535 |
+
|
536 |
+
with gr.Column(elem_id="hn_results_area"):
|
537 |
+
hn_articles_state = gr.State([])
|
538 |
+
|
539 |
+
hn_article_components = []
|
540 |
+
for i in range(100):
|
541 |
+
with gr.Group(visible=False) as article_group:
|
542 |
+
title = gr.Markdown()
|
543 |
+
info = gr.Markdown()
|
544 |
+
|
545 |
+
hn_article_components.append({
|
546 |
+
'group': article_group,
|
547 |
+
'title': title,
|
548 |
+
'info': info,
|
549 |
+
'index': i,
|
550 |
+
})
|
551 |
+
|
552 |
+
|
553 |
+
|
554 |
+
|
555 |
+
|
556 |
+
|
557 |
+
|
558 |
+
# ๊ธฐ์กด ํจ์๋ค
|
559 |
def search_and_display(query, country, articles_state, progress=gr.Progress()):
|
560 |
status_msg = "๊ฒ์์ ์งํ์ค์
๋๋ค. ์ ์๋ง ๊ธฐ๋ค๋ฆฌ์ธ์..."
|
561 |
|
|
|
691 |
outputs[0] = gr.update(value=final_status, visible=True)
|
692 |
yield outputs
|
693 |
|
694 |
+
|
695 |
+
|
696 |
+
|
697 |
+
|
698 |
+
|
699 |
+
# ๊ตญ๊ฐ๋ณ ํญ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
700 |
search_outputs = [
|
701 |
status_message,
|
702 |
translated_query_display,
|
|
|
717 |
show_progress=True
|
718 |
)
|
719 |
|
720 |
+
# ์ ์ธ๊ณ ํญ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
721 |
global_search_outputs = [
|
722 |
status_message_global,
|
723 |
translated_query_display_global,
|
|
|
736 |
outputs=global_search_outputs
|
737 |
)
|
738 |
|
739 |
+
# AI ๋ฆฌํฌํฐ ํญ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
740 |
+
hn_outputs = [status_message_hn]
|
741 |
+
for comp in hn_article_components:
|
742 |
+
hn_outputs.extend([
|
743 |
+
comp['group'],
|
744 |
+
comp['title'],
|
745 |
+
comp['info']
|
746 |
+
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
747 |
|
748 |
+
refresh_button.click(
|
749 |
+
refresh_hn_stories,
|
750 |
+
outputs=hn_outputs
|
751 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
752 |
|
753 |
iface.launch(auth=("it1","chosun1"))
|