seawolf2357 commited on
Commit
76119f7
โ€ข
1 Parent(s): b4a00e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -6,6 +6,7 @@ import asyncio
6
  import subprocess
7
  from datasets import load_dataset
8
  import pandas as pd
 
9
 
10
  # ํ˜„์žฌ ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ ์ถœ๋ ฅ
11
  print("Current Working Directory:", os.getcwd())
@@ -28,13 +29,16 @@ def load_optimized_dataset(data_files):
28
  data_frames = [pd.read_csv(file) for file in data_files]
29
  full_data = pd.concat(data_frames, ignore_index=True)
30
  # ์‚ฌ๊ฑด๋ช…์„ ํ‚ค๋กœ ํ•˜๊ณ  ์‚ฌ๊ฑด๋ฒˆํ˜ธ์™€ ์ „๋ฌธ์„ ์ €์žฅํ•˜๋Š” ๋”•์…”๋„ˆ๋ฆฌ ์ƒ์„ฑ
31
- name_to_number = full_data.set_index('์‚ฌ๊ฑด๋ช…')['์‚ฌ๊ฑด๋ฒˆํ˜ธ'].to_dict()
32
  number_to_fulltext = full_data.set_index('์‚ฌ๊ฑด๋ฒˆํ˜ธ')['์ „๋ฌธ'].to_dict()
33
  return name_to_number, number_to_fulltext
34
 
35
  name_to_number, number_to_fulltext = load_optimized_dataset(data_files)
36
  print("Dataset loaded successfully.")
37
 
 
 
 
38
  # ๋กœ๊น… ์„ค์ •
39
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
40
 
@@ -93,11 +97,17 @@ async def generate_response(message):
93
  global conversation_history
94
  user_input = message.content.strip()
95
  user_mention = message.author.mention
 
 
 
96
 
97
- # ์ž…๋ ฅ์ด ์‚ฌ๊ฑด๋ช…์ธ์ง€ ์‚ฌ๊ฑด๋ฒˆํ˜ธ์ธ์ง€ ํ™•์ธ
98
- if user_input in name_to_number:
99
- case_number = name_to_number[user_input]
100
- system_message = f"{user_mention}, '{user_input}' ์‚ฌ๊ฑด์˜ ์‚ฌ๊ฑด๋ฒˆํ˜ธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:\n์‚ฌ๊ฑด๋ฒˆํ˜ธ: {case_number}"
 
 
 
101
  elif user_input in number_to_fulltext:
102
  full_text = number_to_fulltext[user_input]
103
  system_message = f"{user_mention}, ์‚ฌ๊ฑด๋ฒˆํ˜ธ '{user_input}'์˜ ์ „๋ฌธ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:\n\n{full_text}"
@@ -117,4 +127,4 @@ async def generate_response(message):
117
 
118
  if __name__ == "__main__":
119
  discord_client = MyClient(intents=intents)
120
- discord_client.run(os.getenv('DISCORD_TOKEN'))
 
6
  import subprocess
7
  from datasets import load_dataset
8
  import pandas as pd
9
+ from fuzzywuzzy import process
10
 
11
  # ํ˜„์žฌ ์ž‘์—… ๋””๋ ‰ํ† ๋ฆฌ ์ถœ๋ ฅ
12
  print("Current Working Directory:", os.getcwd())
 
29
  data_frames = [pd.read_csv(file) for file in data_files]
30
  full_data = pd.concat(data_frames, ignore_index=True)
31
  # ์‚ฌ๊ฑด๋ช…์„ ํ‚ค๋กœ ํ•˜๊ณ  ์‚ฌ๊ฑด๋ฒˆํ˜ธ์™€ ์ „๋ฌธ์„ ์ €์žฅํ•˜๋Š” ๋”•์…”๋„ˆ๋ฆฌ ์ƒ์„ฑ
32
+ name_to_number = full_data.groupby('์‚ฌ๊ฑด๋ช…')['์‚ฌ๊ฑด๋ฒˆํ˜ธ'].apply(list).to_dict()
33
  number_to_fulltext = full_data.set_index('์‚ฌ๊ฑด๋ฒˆํ˜ธ')['์ „๋ฌธ'].to_dict()
34
  return name_to_number, number_to_fulltext
35
 
36
  name_to_number, number_to_fulltext = load_optimized_dataset(data_files)
37
  print("Dataset loaded successfully.")
38
 
39
+ # ์‚ฌ๊ฑด๋ช… ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ
40
+ all_case_names = list(name_to_number.keys())
41
+
42
  # ๋กœ๊น… ์„ค์ •
43
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
44
 
 
97
  global conversation_history
98
  user_input = message.content.strip()
99
  user_mention = message.author.mention
100
+
101
+ # ์œ ์‚ฌํ•œ ์‚ฌ๊ฑด๋ช… ์ฐพ๊ธฐ
102
+ matched_case_names = process.extractBests(user_input, all_case_names, limit=3, score_cutoff=80)
103
 
104
+ if matched_case_names:
105
+ case_numbers = []
106
+ for case_name, score in matched_case_names:
107
+ case_numbers.extend(name_to_number[case_name])
108
+ case_numbers = list(set(case_numbers)) # ์ค‘๋ณต ์ œ๊ฑฐ
109
+ case_numbers_str = "\n".join(case_numbers)
110
+ system_message = f"{user_mention}, '{user_input}'์™€ ์œ ์‚ฌํ•œ ์‚ฌ๊ฑด๋ช…์˜ ์‚ฌ๊ฑด๋ฒˆํ˜ธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:\n{case_numbers_str}"
111
  elif user_input in number_to_fulltext:
112
  full_text = number_to_fulltext[user_input]
113
  system_message = f"{user_mention}, ์‚ฌ๊ฑด๋ฒˆํ˜ธ '{user_input}'์˜ ์ „๋ฌธ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:\n\n{full_text}"
 
127
 
128
  if __name__ == "__main__":
129
  discord_client = MyClient(intents=intents)
130
+ discord_client.run(os.getenv('DISCORD_TOKEN'))