dev-yuje commited on
Commit
56d2a83
ยท
1 Parent(s): c64138a

fix: adjust frontend layout scale and add keyword plot script

Browse files
Files changed (2) hide show
  1. app.py +8 -5
  2. 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=700, placeholder=CHATBOT_DESCRIPTION),
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. ์™ผ์ชฝ ์ปฌ๋Ÿผ: ์‚ฌ์ด๋“œ๋ฐ” (๋Œ€์‹œ๋ณด๋“œ ๋ฐ ํ•˜๋‹จ ๋ฉ”๋‰ด) - 3:7 split์„ ์œ„ํ•ด scale=3 ์„ค์ •
378
- with gr.Column(scale=3, min_width=320):
379
  stats_data = get_db_stats()
380
  stats_html = build_stats_html(stats_data)
381
  gr.HTML(stats_html)
382
 
383
- # 3. ์˜ค๋ฅธ์ชฝ ์ปฌ๋Ÿผ: ๋ฉ”์ธ ์ฑ—๋ด‡ ์—์–ด๋ฆฌ์–ด - 3:7 split์„ ์œ„ํ•ด scale=7 ์„ค์ •
384
- with gr.Column(scale=7, min_width=500):
 
 
 
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()