soojeongcrystal commited on
Commit
2e6bb20
โ€ข
1 Parent(s): 6ec37d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -6,22 +6,23 @@ import networkx as nx
6
  import matplotlib.pyplot as plt
7
  import csv
8
  import io
 
9
 
10
  # Sentence-BERT ๋ชจ๋ธ ๋กœ๋“œ
11
  model = SentenceTransformer('all-MiniLM-L6-v2')
12
 
13
- # ์ถ”์ฒœ ๊ฒฐ๊ณผ๋ฅผ CSV ํŒŒ์ผ๋กœ ์ €์žฅํ•˜๋Š” ํ•จ์ˆ˜ (StringIO๋กœ ์ˆ˜์ •)
14
- def save_recommendations_to_csv(recommendations):
15
- output = io.StringIO()
16
- writer = csv.writer(output)
17
- writer.writerow(["Employee ID", "Employee Name", "Recommended Programs"])
18
-
19
- # ์ถ”์ฒœ ๊ฒฐ๊ณผ CSV ํŒŒ์ผ์— ๊ธฐ๋ก
20
- for rec in recommendations:
21
- writer.writerow(rec)
 
22
 
23
- output.seek(0)
24
- return output.getvalue()
25
 
26
  # ์ž๋™์œผ๋กœ ์—ด์„ ๋งค์นญํ•˜๋Š” ํ•จ์ˆ˜
27
  def auto_match_columns(df, required_cols):
@@ -104,12 +105,13 @@ def analyze_data(employee_file, program_file):
104
  plt.title("์ง์›๊ณผ ํ”„๋กœ๊ทธ๋žจ ๊ฐ„์˜ ๊ด€๊ณ„", fontsize=14, fontweight='bold')
105
  plt.tight_layout()
106
 
107
- csv_output = save_recommendations_to_csv(recommendation_rows)
 
108
 
109
  return "\n".join(recommendations), plt.gcf(), csv_output
110
 
111
  # Gradio ๋ธ”๋ก
112
- with gr.Blocks(css=".gradio-button {background-color: #6c757d; color: white;} .gradio-textbox {border-color: #6c757d;}") as demo:
113
  gr.Markdown("<h1 style='text-align: center; color: #2c3e50;'>๐Ÿ’ผ HybridRAG ์‹œ์Šคํ…œ</h1>")
114
 
115
  with gr.Row():
 
6
  import matplotlib.pyplot as plt
7
  import csv
8
  import io
9
+ import os
10
 
11
  # Sentence-BERT ๋ชจ๋ธ ๋กœ๋“œ
12
  model = SentenceTransformer('all-MiniLM-L6-v2')
13
 
14
+ # ์ถ”์ฒœ ๊ฒฐ๊ณผ๋ฅผ ์‹ค์ œ ํŒŒ์ผ๋กœ ์ €์žฅํ•˜๋Š” ํ•จ์ˆ˜
15
+ def save_recommendations_to_file(recommendations):
16
+ file_path = "recommendations.csv"
17
+ with open(file_path, mode='w', newline='', encoding='utf-8') as file:
18
+ writer = csv.writer(file)
19
+ writer.writerow(["Employee ID", "Employee Name", "Recommended Programs"])
20
+
21
+ # ์ถ”์ฒœ ๊ฒฐ๊ณผ CSV ํŒŒ์ผ์— ๊ธฐ๋ก
22
+ for rec in recommendations:
23
+ writer.writerow(rec)
24
 
25
+ return file_path
 
26
 
27
  # ์ž๋™์œผ๋กœ ์—ด์„ ๋งค์นญํ•˜๋Š” ํ•จ์ˆ˜
28
  def auto_match_columns(df, required_cols):
 
105
  plt.title("์ง์›๊ณผ ํ”„๋กœ๊ทธ๋žจ ๊ฐ„์˜ ๊ด€๊ณ„", fontsize=14, fontweight='bold')
106
  plt.tight_layout()
107
 
108
+ # CSV ํŒŒ์ผ๋กœ ์ถ”์ฒœ ๊ฒฐ๊ณผ ๋ฐ˜ํ™˜
109
+ csv_output = save_recommendations_to_file(recommendation_rows)
110
 
111
  return "\n".join(recommendations), plt.gcf(), csv_output
112
 
113
  # Gradio ๋ธ”๋ก
114
+ with gr.Blocks(css=".gradio-button {background-color: #007bff; color: white;} .gradio-textbox {border-color: #6c757d;}") as demo:
115
  gr.Markdown("<h1 style='text-align: center; color: #2c3e50;'>๐Ÿ’ผ HybridRAG ์‹œ์Šคํ…œ</h1>")
116
 
117
  with gr.Row():