Spaces:
Running
Running
seawolf2357
commited on
Commit
โข
76119f7
1
Parent(s):
b4a00e6
Update app.py
Browse files
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.
|
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 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
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'))
|