Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -201,7 +201,7 @@ def fetch_related_keywords(keyword):
|
|
201 |
CUSTOMER_ID = get_env_variable("NAVER_CUSTOMER_ID")
|
202 |
|
203 |
if not all([API_KEY, SECRET_KEY, CUSTOMER_ID]):
|
204 |
-
debug_log(f"๋ค์ด๋ฒ ๊ด๊ณ API ํค ์ ๋ณด ๋ถ์กฑ์ผ๋ก '{keyword}' ์ฐ๊ด ํค์๋ ์กฐํ๋ฅผ ๊ฑด๋<0xEB><0xB5>๋๋ค.")
|
205 |
return pd.DataFrame()
|
206 |
|
207 |
BASE_URL = "https://api.naver.com"
|
@@ -274,7 +274,7 @@ def fetch_blog_count(keyword):
|
|
274 |
client_secret = get_env_variable("NAVER_SEARCH_CLIENT_SECRET")
|
275 |
|
276 |
if not client_id or not client_secret:
|
277 |
-
debug_log(f"๋ค์ด๋ฒ ๊ฒ์ API ํค ์ ๋ณด ๋ถ์กฑ์ผ๋ก '{keyword}' ๋ธ๋ก๊ทธ ์ ์กฐํ๋ฅผ ๊ฑด๋<0xEB><0xB5>๋๋ค.")
|
278 |
return 0
|
279 |
|
280 |
url = "https://openapi.naver.com/v1/search/blog.json"
|
@@ -536,7 +536,8 @@ def combined_analysis(blog_text: str, remove_freq1: bool, direct_keyword_input:
|
|
536 |
for col in cols:
|
537 |
if col not in df_morph.columns:
|
538 |
df_morph[col] = "" if col == "์ง์ ์
๋ ฅ" else (0 if col != "๋จ์ด" else "")
|
539 |
-
df_morph
|
|
|
540 |
return df_morph, create_excel_file(df_morph)
|
541 |
|
542 |
# ์ง์ ์
๋ ฅ ํค์๋์ ๋ํ ์ ๋ณด (๋น๋์, API ์ ๋ณด) ๊ฐ์ ธ์ค๊ธฐ
|
@@ -562,14 +563,6 @@ def combined_analysis(blog_text: str, remove_freq1: bool, direct_keyword_input:
|
|
562 |
# df_morph์ ์๋ ๋จ์ด๋ df_morph ์ ๋ณด๋ฅผ ์ฐ์ ์ฌ์ฉ (์ง์ ์
๋ ฅ ํ๋๊ทธ๋ง ์
๋ฐ์ดํธ)
|
563 |
# df_direct_raw์์ df_morph์ ์๋ ๋จ์ด๋ง ๊ณจ๋ผ์ ์ถ๊ฐ
|
564 |
|
565 |
-
# ํฉ์น๊ธฐ: df_morph๋ฅผ ๊ธฐ์ค์ผ๋ก df_direct_raw์ ์ ๋ณด๋ฅผ ์ถ๊ฐ/์
๋ฐ์ดํธ
|
566 |
-
# Pandas 0.25.0 ์ด์์์๋ combine_first์ overwrite ๋์์ด ์ฝ๊ฐ ๋ค๋ฅผ ์ ์์ผ๋ฏ๋ก merge ์ฌ์ฉ ๊ณ ๋ ค
|
567 |
-
|
568 |
-
# 1. df_morph์ ๋จ์ด๋ค์ ๋ํด df_direct_raw์ ์ ๋ณด๋ก ์
๋ฐ์ดํธ (API ์ ๋ณด ๋ฑ)
|
569 |
-
# ๋จ, ๋น๋์๋ ๊ฐ์ ๊ณ์ฐํ ๊ฒ์ ์ ์งํ ์ง, ์๋๋ฉด ํ์ชฝ์ ํํ ์ง ๊ฒฐ์ ํ์.
|
570 |
-
# ์ฌ๊ธฐ์๋ df_morph์ ๋น๋์(ํํ์๋ถ์ ๊ธฐ๋ฐ)์ df_direct_raw์ ๋น๋์(๋จ์ count)๊ฐ ๋ค๋ฅผ ์ ์์.
|
571 |
-
# ์ผ๋จ์ df_morph ๊ธฐ์ค์ผ๋ก ํ๊ณ , ์๋ ์ง์ ํค์๋๋ง df_direct_raw์์ ์ถ๊ฐํ๋ ๋ฐฉ์.
|
572 |
-
|
573 |
# df_morph์ '์ง์ ์
๋ ฅ' ์ปฌ๋ผ์ ์ด๋ฏธ ์์์ ์ฒ๋ฆฌ๋จ.
|
574 |
# ์ด์ df_direct_raw์๋ง ์๋ ํค์๋๋ฅผ df_morph์ ์ถ๊ฐ
|
575 |
|
@@ -603,15 +596,16 @@ def combined_analysis(blog_text: str, remove_freq1: bool, direct_keyword_input:
|
|
603 |
|
604 |
# NA ๊ฐ๋ค์ ์ ์ ํ ์ฒ๋ฆฌ (์: 0์ผ๋ก ์ฑ์ฐ๊ฑฐ๋ ๊ทธ๋๋ก ๋๊ธฐ)
|
605 |
# API ๊ฐ๋ค์ ์ซ์๊ฐ ์๋ ์ ์์ผ๋ฏ๋ก (์: "< 10"), process_keyword์์ ์ฒ๋ฆฌ๋จ. ์ฌ๊ธฐ์๋ intํ ๋ณํ ์ ์ด๋ฏ๋ก ๊ทธ๋๋ก ๋ .
|
606 |
-
# Gradio
|
607 |
# ๋น๋์๋ ์ ์ํ์ด์ด์ผ ํจ
|
608 |
if "๋น๋์" in combined_df.columns:
|
609 |
combined_df["๋น๋์"] = combined_df["๋น๋์"].fillna(0).astype(int)
|
610 |
|
611 |
|
612 |
-
|
613 |
-
|
614 |
-
|
|
|
615 |
|
616 |
combined_excel = create_excel_file(combined_df)
|
617 |
debug_log("combined_analysis ํจ์ ์๋ฃ")
|
@@ -781,11 +775,11 @@ with gr.Blocks(title="๋ค์ด๋ฒ ๋ธ๋ก๊ทธ ํค์๋ ๋ถ์ ์๋น์ค", css=custo
|
|
781 |
with gr.Column(scale=3): # ์ค๋ฅธ์ชฝ ์ปฌ๋ผ (๊ฒฐ๊ณผ ์์ญ)
|
782 |
with gr.Group(elem_classes="custom-group custom-result"):
|
783 |
gr.Markdown("### ๋ถ์ ๊ฒฐ๊ณผ")
|
784 |
-
result_df_display = gr.Dataframe
|
785 |
label="ํตํฉ ๋ถ์ ๊ฒฐ๊ณผ (๋จ์ด, ๋น๋์, ๊ฒ์๋, ๋ธ๋ก๊ทธ๋ฌธ์์, ์ง์ ์
๋ ฅ ์ฌ๋ถ)",
|
786 |
-
interactive=False,
|
787 |
-
height=600,
|
788 |
-
wrap=True
|
789 |
)
|
790 |
with gr.Group(elem_classes="custom-group"):
|
791 |
gr.Markdown("### ๊ฒฐ๊ณผ ๋ค์ด๋ก๋")
|
|
|
201 |
CUSTOMER_ID = get_env_variable("NAVER_CUSTOMER_ID")
|
202 |
|
203 |
if not all([API_KEY, SECRET_KEY, CUSTOMER_ID]):
|
204 |
+
debug_log(f"๋ค์ด๋ฒ ๊ด๊ณ API ํค ์ ๋ณด ๋ถ์กฑ์ผ๋ก '{keyword}' ์ฐ๊ด ํค์๋ ์กฐํ๋ฅผ ๊ฑด๋<0xEB><0x8><0xB5>๋๋ค.")
|
205 |
return pd.DataFrame()
|
206 |
|
207 |
BASE_URL = "https://api.naver.com"
|
|
|
274 |
client_secret = get_env_variable("NAVER_SEARCH_CLIENT_SECRET")
|
275 |
|
276 |
if not client_id or not client_secret:
|
277 |
+
debug_log(f"๋ค์ด๋ฒ ๊ฒ์ API ํค ์ ๋ณด ๋ถ์กฑ์ผ๋ก '{keyword}' ๋ธ๋ก๊ทธ ์ ์กฐํ๋ฅผ ๊ฑด๋<0xEB><0x8><0xB5>๋๋ค.")
|
278 |
return 0
|
279 |
|
280 |
url = "https://openapi.naver.com/v1/search/blog.json"
|
|
|
536 |
for col in cols:
|
537 |
if col not in df_morph.columns:
|
538 |
df_morph[col] = "" if col == "์ง์ ์
๋ ฅ" else (0 if col != "๋จ์ด" else "")
|
539 |
+
if not df_morph.empty: # df_morph๊ฐ ๋น์ด์์ง ์์ ๋๋ง ์ปฌ๋ผ ์์ ์ ์ฉ
|
540 |
+
df_morph = df_morph[cols]
|
541 |
return df_morph, create_excel_file(df_morph)
|
542 |
|
543 |
# ์ง์ ์
๋ ฅ ํค์๋์ ๋ํ ์ ๋ณด (๋น๋์, API ์ ๋ณด) ๊ฐ์ ธ์ค๊ธฐ
|
|
|
563 |
# df_morph์ ์๋ ๋จ์ด๋ df_morph ์ ๋ณด๋ฅผ ์ฐ์ ์ฌ์ฉ (์ง์ ์
๋ ฅ ํ๋๊ทธ๋ง ์
๋ฐ์ดํธ)
|
564 |
# df_direct_raw์์ df_morph์ ์๋ ๋จ์ด๋ง ๊ณจ๋ผ์ ์ถ๊ฐ
|
565 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
566 |
# df_morph์ '์ง์ ์
๋ ฅ' ์ปฌ๋ผ์ ์ด๋ฏธ ์์์ ์ฒ๋ฆฌ๋จ.
|
567 |
# ์ด์ df_direct_raw์๋ง ์๋ ํค์๋๋ฅผ df_morph์ ์ถ๊ฐ
|
568 |
|
|
|
596 |
|
597 |
# NA ๊ฐ๋ค์ ์ ์ ํ ์ฒ๋ฆฌ (์: 0์ผ๋ก ์ฑ์ฐ๊ฑฐ๋ ๊ทธ๋๋ก ๋๊ธฐ)
|
598 |
# API ๊ฐ๋ค์ ์ซ์๊ฐ ์๋ ์ ์์ผ๋ฏ๋ก (์: "< 10"), process_keyword์์ ์ฒ๋ฆฌ๋จ. ์ฌ๊ธฐ์๋ intํ ๋ณํ ์ ์ด๋ฏ๋ก ๊ทธ๋๋ก ๋ .
|
599 |
+
# Gradio DataFrame์ None์ ์ ํ์ํจ.
|
600 |
# ๋น๋์๋ ์ ์ํ์ด์ด์ผ ํจ
|
601 |
if "๋น๋์" in combined_df.columns:
|
602 |
combined_df["๋น๋์"] = combined_df["๋น๋์"].fillna(0).astype(int)
|
603 |
|
604 |
|
605 |
+
if not combined_df.empty : # ๋น์ด์์ง ์์ ๋๋ง ์ ๋ ฌ ๋ฐ ์ค๋ณต ์ ๊ฑฐ
|
606 |
+
combined_df = combined_df[final_cols_combined].drop_duplicates(subset=['๋จ์ด'], keep='first') # ๋ง์ฝ์ ์ํ ์ค๋ณต ์ ๊ฑฐ
|
607 |
+
combined_df.sort_values(by=["์ง์ ์
๋ ฅ", "๋น๋์"], ascending=[False, False], inplace=True, na_position='last') # ์ง์ ์
๋ ฅ ์ฐ์ , ๊ทธ ๋ค์ ๋น๋์
|
608 |
+
combined_df.reset_index(drop=True, inplace=True)
|
609 |
|
610 |
combined_excel = create_excel_file(combined_df)
|
611 |
debug_log("combined_analysis ํจ์ ์๋ฃ")
|
|
|
775 |
with gr.Column(scale=3): # ์ค๋ฅธ์ชฝ ์ปฌ๋ผ (๊ฒฐ๊ณผ ์์ญ)
|
776 |
with gr.Group(elem_classes="custom-group custom-result"):
|
777 |
gr.Markdown("### ๋ถ์ ๊ฒฐ๊ณผ")
|
778 |
+
result_df_display = gr.DataFrame( # gr.Dataframe -> gr.DataFrame ์ผ๋ก ๋ณ๊ฒฝ
|
779 |
label="ํตํฉ ๋ถ์ ๊ฒฐ๊ณผ (๋จ์ด, ๋น๋์, ๊ฒ์๋, ๋ธ๋ก๊ทธ๋ฌธ์์, ์ง์ ์
๋ ฅ ์ฌ๋ถ)",
|
780 |
+
interactive=False,
|
781 |
+
# height=600, # Gradio ๋ฒ์ ํธํ์ฑ์ ์๏ฟฝ๏ฟฝ height ํ๋ผ๋ฏธํฐ ์ ๊ฑฐ ๋๋ ์ฃผ์ ์ฒ๋ฆฌ
|
782 |
+
wrap=True
|
783 |
)
|
784 |
with gr.Group(elem_classes="custom-group"):
|
785 |
gr.Markdown("### ๊ฒฐ๊ณผ ๋ค์ด๋ก๋")
|