Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Commit
โข
104f578
1
Parent(s):
aece062
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ from huggingface_hub import InferenceClient
|
|
5 |
import asyncio
|
6 |
import subprocess
|
7 |
from datasets import load_dataset
|
|
|
8 |
|
9 |
# ํ์ฌ ์์
๋๋ ํ ๋ฆฌ ์ถ๋ ฅ
|
10 |
print("Current Working Directory:", os.getcwd())
|
@@ -22,8 +23,16 @@ if missing_files:
|
|
22 |
else:
|
23 |
print("All files are present in the current directory.")
|
24 |
|
25 |
-
# ๋ฐ์ดํฐ์
๋ก๋
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
print("Dataset loaded successfully.")
|
28 |
|
29 |
# ๋ก๊น
์ค์
|
@@ -36,7 +45,7 @@ intents.messages = True
|
|
36 |
intents.guilds = True
|
37 |
intents.guild_messages = True
|
38 |
|
39 |
-
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
40 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
|
41 |
|
42 |
# ํน์ ์ฑ๋ ID
|
@@ -81,43 +90,25 @@ class MyClient(discord.Client):
|
|
81 |
|
82 |
async def generate_response(message):
|
83 |
global conversation_history
|
84 |
-
|
85 |
user_mention = message.author.mention
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
for i in range(0, len(full_response_text), max_length):
|
95 |
-
part_response = full_response_text[i:i+max_length]
|
96 |
-
await message.channel.send(part_response)
|
97 |
-
response_parts.append(part_response)
|
98 |
-
logging.debug(f'Full model response sent: {full_response_text}')
|
99 |
-
conversation_history.append({"role": "assistant", "content": full_response_text})
|
100 |
-
return "".join(response_parts) # ์กฐ๊ฐ๋ ๋ฉ์์ง๋ค์ ์ฐ๊ฒฐํ์ฌ ๋ฐํ
|
101 |
else:
|
102 |
-
|
103 |
-
logging.debug(f'Full model response sent: {full_response_text}')
|
104 |
-
conversation_history.append({"role": "assistant", "content": full_response_text})
|
105 |
-
return full_response_text # ์ ์ฒด ๋ฉ์์ง๋ฅผ ๋ฐํ
|
106 |
-
|
107 |
-
return "" # ๋ฐํ ๊ฐ์ด ์์ ๊ฒฝ์ฐ ๋น ๋ฌธ์์ด ๋ฐํ
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
return "๊ด๋ จ ๋ฒ๋ฅ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
|
114 |
-
|
115 |
-
def search_in_dataset_by_case_number(case_number, dataset):
|
116 |
-
for record in dataset['train']:
|
117 |
-
if record['์ฌ๊ฑด๋ฒํธ'] == case_number:
|
118 |
-
return record.get('์ ๋ฌธ', "ํด๋น ์ฌ๊ฑด์ ๋ํ ์ ๋ฌธ ์ ๋ณด๊ฐ ์์ต๋๋ค.")
|
119 |
-
return "๊ด๋ จ ๋ฒ๋ฅ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
|
120 |
|
121 |
if __name__ == "__main__":
|
122 |
discord_client = MyClient(intents=intents)
|
123 |
discord_client.run(os.getenv('DISCORD_TOKEN'))
|
|
|
|
5 |
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())
|
|
|
23 |
else:
|
24 |
print("All files are present in the current directory.")
|
25 |
|
26 |
+
# ๋ฐ์ดํฐ์
๋ก๋ ๋ฐ ์ต์ ํ
|
27 |
+
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 |
# ๋ก๊น
์ค์
|
|
|
45 |
intents.guilds = True
|
46 |
intents.guild_messages = True
|
47 |
|
48 |
+
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์ (์์๋ก ํฌํจ, ์ค์ ๋ก ์ฌ์ฉ๋์ง ์์)
|
49 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
|
50 |
|
51 |
# ํน์ ์ฑ๋ ID
|
|
|
90 |
|
91 |
async def generate_response(message):
|
92 |
global conversation_history
|
93 |
+
user_input = message.content.strip()
|
94 |
user_mention = message.author.mention
|
95 |
+
|
96 |
+
# ์
๋ ฅ์ด ์ฌ๊ฑด๋ช
์ธ์ง ์ฌ๊ฑด๋ฒํธ์ธ์ง ํ์ธ
|
97 |
+
if user_input in name_to_number:
|
98 |
+
case_number = name_to_number[user_input]
|
99 |
+
system_message = f"{user_mention}, '{user_input}' ์ฌ๊ฑด์ ์ฌ๊ฑด๋ฒํธ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:\n์ฌ๊ฑด๋ฒํธ: {case_number}"
|
100 |
+
elif user_input in number_to_fulltext:
|
101 |
+
full_text = number_to_fulltext[user_input]
|
102 |
+
system_message = f"{user_mention}, ์ฌ๊ฑด๋ฒํธ '{user_input}'์ ์ ๋ฌธ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค:\n\n{full_text}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
else:
|
104 |
+
system_message = f"{user_mention}, ๊ด๋ จ ๋ฒ๋ฅ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
+
# ์๋ต ๋ณด๋ด๊ธฐ
|
107 |
+
await message.channel.send(system_message)
|
108 |
+
logging.debug(f'Full model response sent: {system_message}')
|
109 |
+
conversation_history.append({"role": "assistant", "content": system_message})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
if __name__ == "__main__":
|
112 |
discord_client = MyClient(intents=intents)
|
113 |
discord_client.run(os.getenv('DISCORD_TOKEN'))
|
114 |
+
|