soojeongcrystal commited on
Commit
ca15903
β€’
1 Parent(s): 9d9c526

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -12,10 +12,11 @@ from datetime import datetime, timedelta
12
  # ν•œκ΅­μ–΄ 처리λ₯Ό μœ„ν•œ KoSentence-BERT λͺ¨λΈ λ‘œλ“œ
13
  model = SentenceTransformer('jhgan/ko-sbert-sts')
14
 
15
- # λ‚˜λˆ”λ°”λ₯Έκ³ λ”• 폰트 μ„€μ •
16
  font_path = "./NanumBarunGothic.ttf"
17
  font_prop = fm.FontProperties(fname=font_path)
18
- plt.rcParams['font.family'] = font_prop.get_name()
 
 
19
 
20
  # μ „μ—­ λ³€μˆ˜
21
  global_recommendations = None
@@ -31,16 +32,15 @@ def create_csv_string(recommendations):
31
  writer.writerow(rec)
32
  return output.getvalue()
33
 
34
- # 차트 생성 ν•¨μˆ˜
35
  def create_chart(G):
36
  plt.figure(figsize=(10, 8))
37
  pos = nx.spring_layout(G)
38
  nx.draw(G, pos, with_labels=True, node_color='lightblue', node_size=3000, font_size=10, font_weight='bold', edge_color='gray')
39
  plt.title("직원과 ν”„λ‘œκ·Έλž¨ κ°„μ˜ 관계", fontsize=14, fontweight='bold')
40
- plt.tight_layout()
41
 
42
  buf = io.BytesIO()
43
- plt.savefig(buf, format='png')
44
  buf.seek(0)
45
  plt.close()
46
  return buf
@@ -76,8 +76,11 @@ def validate_and_get_columns(employee_df, program_df):
76
  return None, employee_cols, program_cols
77
 
78
  # 유튜브 데이터 μ—΄ 선택 ν•¨μˆ˜
 
79
  def select_youtube_columns(youtube_file):
80
  global youtube_columns
 
 
81
  youtube_df = pd.read_csv(youtube_file.name)
82
  required_youtube_cols = ["title", "description", "url", "upload_date"]
83
  youtube_columns = auto_match_columns(youtube_df, required_youtube_cols)
@@ -194,9 +197,9 @@ def hybrid_rag(employee_file, program_file, youtube_file, title_col, description
194
 
195
  # κ²°κ³Ό ν…Œμ΄λΈ” λ°μ΄ν„°ν”„λ ˆμž„ 생성
196
  result_df = pd.DataFrame(recommendation_rows, columns=["Employee ID", "Employee Name", "Recommended Programs", "Recommended YouTube Content"])
197
-
198
- return result_df, chart_buffer, gr.File(value=global_csv_string, visible=True), gr.Button.update(visible=True)
199
 
 
 
200
  # μ±„νŒ… 응닡 ν•¨μˆ˜
201
  def chat_response(message, history):
202
  global global_recommendations
 
12
  # ν•œκ΅­μ–΄ 처리λ₯Ό μœ„ν•œ KoSentence-BERT λͺ¨λΈ λ‘œλ“œ
13
  model = SentenceTransformer('jhgan/ko-sbert-sts')
14
 
 
15
  font_path = "./NanumBarunGothic.ttf"
16
  font_prop = fm.FontProperties(fname=font_path)
17
+ plt.rcParams['font.family'] = 'NanumBarunGothic'
18
+ plt.rcParams['font.sans-serif'] = ['NanumBarunGothic']
19
+ fm.fontManager.addfont(font_path)
20
 
21
  # μ „μ—­ λ³€μˆ˜
22
  global_recommendations = None
 
32
  writer.writerow(rec)
33
  return output.getvalue()
34
 
 
35
  def create_chart(G):
36
  plt.figure(figsize=(10, 8))
37
  pos = nx.spring_layout(G)
38
  nx.draw(G, pos, with_labels=True, node_color='lightblue', node_size=3000, font_size=10, font_weight='bold', edge_color='gray')
39
  plt.title("직원과 ν”„λ‘œκ·Έλž¨ κ°„μ˜ 관계", fontsize=14, fontweight='bold')
40
+ plt.tight_layout(pad=1.0)
41
 
42
  buf = io.BytesIO()
43
+ plt.savefig(buf, format='png', bbox_inches='tight')
44
  buf.seek(0)
45
  plt.close()
46
  return buf
 
76
  return None, employee_cols, program_cols
77
 
78
  # 유튜브 데이터 μ—΄ 선택 ν•¨μˆ˜
79
+
80
  def select_youtube_columns(youtube_file):
81
  global youtube_columns
82
+ if youtube_file is None:
83
+ return [gr.Dropdown(choices=[], value="") for _ in range(4)]
84
  youtube_df = pd.read_csv(youtube_file.name)
85
  required_youtube_cols = ["title", "description", "url", "upload_date"]
86
  youtube_columns = auto_match_columns(youtube_df, required_youtube_cols)
 
197
 
198
  # κ²°κ³Ό ν…Œμ΄λΈ” λ°μ΄ν„°ν”„λ ˆμž„ 생성
199
  result_df = pd.DataFrame(recommendation_rows, columns=["Employee ID", "Employee Name", "Recommended Programs", "Recommended YouTube Content"])
 
 
200
 
201
+ return result_df, chart_buffer, gr.File(value=global_csv_string, visible=True), gr.Button(value="CSV λ‹€μš΄λ‘œλ“œ", visible=True)
202
+
203
  # μ±„νŒ… 응닡 ν•¨μˆ˜
204
  def chat_response(message, history):
205
  global global_recommendations