fix: adjust frontend layout scale and add keyword plot script
Browse files- app.py +8 -5
- plot_keywords.py +60 -0
app.py
CHANGED
|
@@ -326,7 +326,7 @@ CHATBOT_DESCRIPTION = """
|
|
| 326 |
|
| 327 |
interface_kwargs = {
|
| 328 |
"fn": chat,
|
| 329 |
-
"chatbot": gr.Chatbot(height=
|
| 330 |
"textbox": gr.Textbox(
|
| 331 |
placeholder="๋ถ์ํ๊ณ ์ถ์ ๋ด์ฉ์ ์์ฐ์ด๋ก ์
๋ ฅํด์ฃผ์ธ์...",
|
| 332 |
container=False,
|
|
@@ -374,14 +374,17 @@ with gr.Blocks(**blocks_kwargs) as demo:
|
|
| 374 |
""")
|
| 375 |
|
| 376 |
with gr.Row():
|
| 377 |
-
# 2. ์ผ์ชฝ ์ปฌ๋ผ: ์ฌ์ด๋๋ฐ (๋์๋ณด๋ ๋ฐ ํ๋จ ๋ฉ๋ด) -
|
| 378 |
-
with gr.Column(scale=
|
| 379 |
stats_data = get_db_stats()
|
| 380 |
stats_html = build_stats_html(stats_data)
|
| 381 |
gr.HTML(stats_html)
|
| 382 |
|
| 383 |
-
# 3. ์ค๋ฅธ์ชฝ ์ปฌ๋ผ: ๋ฉ์ธ ์ฑ๋ด ์์ด๋ฆฌ์ด -
|
| 384 |
-
with gr.Column(scale=
|
|
|
|
|
|
|
|
|
|
| 385 |
# ChatInterface without redundant titles/descriptions
|
| 386 |
chatbot_interface_kwargs = interface_kwargs.copy()
|
| 387 |
chatbot_interface_kwargs.pop("title", None)
|
|
|
|
| 326 |
|
| 327 |
interface_kwargs = {
|
| 328 |
"fn": chat,
|
| 329 |
+
"chatbot": gr.Chatbot(height=650),
|
| 330 |
"textbox": gr.Textbox(
|
| 331 |
placeholder="๋ถ์ํ๊ณ ์ถ์ ๋ด์ฉ์ ์์ฐ์ด๋ก ์
๋ ฅํด์ฃผ์ธ์...",
|
| 332 |
container=False,
|
|
|
|
| 374 |
""")
|
| 375 |
|
| 376 |
with gr.Row():
|
| 377 |
+
# 2. ์ผ์ชฝ ์ปฌ๋ผ: ์ฌ์ด๋๋ฐ (๋์๋ณด๋ ๋ฐ ํ๋จ ๋ฉ๋ด) - ๋์ด๋ฅผ ์ค์ด๊ธฐ ์ํด scale=2 ์ค์
|
| 378 |
+
with gr.Column(scale=2, min_width=280):
|
| 379 |
stats_data = get_db_stats()
|
| 380 |
stats_html = build_stats_html(stats_data)
|
| 381 |
gr.HTML(stats_html)
|
| 382 |
|
| 383 |
+
# 3. ์ค๋ฅธ์ชฝ ์ปฌ๋ผ: ๋ฉ์ธ ์ฑ๋ด ์์ด๋ฆฌ์ด - ๋๊ฒ ์ฐ๊ธฐ ์ํด scale=8 ์ค์
|
| 384 |
+
with gr.Column(scale=8, min_width=600):
|
| 385 |
+
# ์ฐ์ธก ์ค๋ช
์์ญ ๋ณต๊ตฌ (Chatbot placeholder ๋์ HTML๋ก ์ง์ ๋ ๋๋ง)
|
| 386 |
+
gr.HTML(CHATBOT_DESCRIPTION)
|
| 387 |
+
|
| 388 |
# ChatInterface without redundant titles/descriptions
|
| 389 |
chatbot_interface_kwargs = interface_kwargs.copy()
|
| 390 |
chatbot_interface_kwargs.pop("title", None)
|
plot_keywords.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import dotenv
|
| 3 |
+
import neo4j
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
import matplotlib.font_manager as fm
|
| 7 |
+
|
| 8 |
+
dotenv.load_dotenv()
|
| 9 |
+
|
| 10 |
+
# Windows ํ๊ฒฝ ํ๊ธ ํฐํธ ์ค์
|
| 11 |
+
plt.rc('font', family='Malgun Gothic')
|
| 12 |
+
plt.rcParams['axes.unicode_minus'] = False
|
| 13 |
+
|
| 14 |
+
def create_keyword_plot():
|
| 15 |
+
driver = neo4j.GraphDatabase.driver(
|
| 16 |
+
os.getenv('NEO4J_URI'),
|
| 17 |
+
auth=(os.getenv('NEO4J_USERNAME'), os.getenv('NEO4J_PASSWORD'))
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
query = """
|
| 21 |
+
MATCH (a:Article)-[:MENTIONS]->(n)
|
| 22 |
+
WHERE NOT n:Content
|
| 23 |
+
RETURN n.name AS keyword, count(a) AS freq
|
| 24 |
+
ORDER BY freq DESC
|
| 25 |
+
LIMIT 20
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
with driver.session() as session:
|
| 29 |
+
res = session.run(query)
|
| 30 |
+
data = [dict(record) for record in res]
|
| 31 |
+
|
| 32 |
+
driver.close()
|
| 33 |
+
|
| 34 |
+
if not data:
|
| 35 |
+
print("ํค์๋ ๋ฐ์ดํฐ๊ฐ ์์ต๋๋ค.")
|
| 36 |
+
return
|
| 37 |
+
|
| 38 |
+
df = pd.DataFrame(data)
|
| 39 |
+
|
| 40 |
+
# ๋ง๋ ๊ทธ๋ํ ๊ทธ๋ฆฌ๊ธฐ (์ญ์์ผ๋ก ์ ๋ ฌํ์ฌ ๊ฐ์ฅ ๋ง์ ๊ฒ์ด ์๋ก ์ค๊ฒ ํจ)
|
| 41 |
+
plt.figure(figsize=(10, 8))
|
| 42 |
+
bars = plt.barh(df['keyword'][::-1], df['freq'][::-1], color='#3b5a82')
|
| 43 |
+
|
| 44 |
+
plt.xlabel('์ถํ ๋น๋ (๊ด๋ จ ๊ธฐ์ฌ ์)', fontsize=12)
|
| 45 |
+
plt.ylabel('ํค์๋ (๊ธฐ์
/๊ธฐ์ /์๋น์ค)', fontsize=12)
|
| 46 |
+
plt.title('์์ 20๊ฐ AI ๊ด๋ จ ํค์๋ ์ถํ ๋น๋', fontsize=16, fontweight='bold')
|
| 47 |
+
|
| 48 |
+
# ๋ง๋ ์์ ์์น ํ
์คํธ ํ์
|
| 49 |
+
for bar in bars:
|
| 50 |
+
width = bar.get_width()
|
| 51 |
+
plt.text(width + 0.1, bar.get_y() + bar.get_height()/2, f'{int(width)}',
|
| 52 |
+
ha='left', va='center', fontsize=10)
|
| 53 |
+
|
| 54 |
+
plt.tight_layout()
|
| 55 |
+
output_path = 'keyword_frequencies.png'
|
| 56 |
+
plt.savefig(output_path, dpi=300, bbox_inches='tight')
|
| 57 |
+
print(f"Graph successfully saved to {output_path}")
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
create_keyword_plot()
|