Update app.py
Browse files
app.py
CHANGED
@@ -1,736 +1,2 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
import os
|
4 |
-
|
5 |
-
from typing import List, Dict, Tuple
|
6 |
-
import json
|
7 |
-
import io
|
8 |
-
import traceback
|
9 |
-
import csv
|
10 |
-
from openai import OpenAI
|
11 |
-
from functools import lru_cache
|
12 |
-
from concurrent.futures import ThreadPoolExecutor
|
13 |
-
import math
|
14 |
-
|
15 |
-
# CSS ์ค์
|
16 |
-
css = """
|
17 |
-
footer {
|
18 |
-
visibility: hidden;
|
19 |
-
}
|
20 |
-
#chatbot-container, #chatbot-data-upload {
|
21 |
-
height: 700px;
|
22 |
-
overflow-y: scroll;
|
23 |
-
}
|
24 |
-
#chatbot-container .message, #chatbot-data-upload .message {
|
25 |
-
font-size: 14px;
|
26 |
-
}
|
27 |
-
/* ์
๋ ฅ์ฐฝ ๋ฐฐ๊ฒฝ์ ๋ฐ ๊ธ์์ ๋ณ๊ฒฝ */
|
28 |
-
textarea, input[type="text"] {
|
29 |
-
background-color: #ffffff;
|
30 |
-
color: #000000;
|
31 |
-
}
|
32 |
-
/* ํ์ผ ์
๋ก๋ ์์ญ ๋์ด ์กฐ์ */
|
33 |
-
#parquet-upload-area {
|
34 |
-
max-height: 150px;
|
35 |
-
overflow-y: auto;
|
36 |
-
}
|
37 |
-
/* ์ด๊ธฐ ์ค๋ช
๊ธ์จ ํฌ๊ธฐ ์กฐ์ */
|
38 |
-
#initial-description {
|
39 |
-
font-size: 14px;
|
40 |
-
}
|
41 |
-
/* API Key ์
๋ ฅ ์น์
์คํ์ผ */
|
42 |
-
.api-key-section {
|
43 |
-
margin: 10px 0;
|
44 |
-
padding: 10px;
|
45 |
-
border: 1px solid #ddd;
|
46 |
-
border-radius: 5px;
|
47 |
-
}
|
48 |
-
.api-key-status {
|
49 |
-
margin-top: 5px;
|
50 |
-
font-weight: bold;
|
51 |
-
}
|
52 |
-
"""
|
53 |
-
|
54 |
-
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
55 |
-
hf_client = InferenceClient(
|
56 |
-
"CohereForAI/c4ai-command-r-plus-08-2024", token=os.getenv("HF_TOKEN")
|
57 |
-
)
|
58 |
-
|
59 |
-
def load_code(filename: str) -> str:
|
60 |
-
try:
|
61 |
-
with open(filename, 'r', encoding='utf-8') as file:
|
62 |
-
return file.read()
|
63 |
-
except FileNotFoundError:
|
64 |
-
return f"{filename} ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
65 |
-
except Exception as e:
|
66 |
-
return f"ํ์ผ์ ์ฝ๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
67 |
-
|
68 |
-
def load_parquet(filename: str) -> str:
|
69 |
-
try:
|
70 |
-
df = pd.read_parquet(filename, engine='pyarrow')
|
71 |
-
return df.head(10).to_markdown(index=False)
|
72 |
-
except FileNotFoundError:
|
73 |
-
return f"{filename} ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค."
|
74 |
-
except Exception as e:
|
75 |
-
return f"ํ์ผ์ ์ฝ๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
76 |
-
|
77 |
-
def clean_response(text: str) -> str:
|
78 |
-
"""์๋ต ํ
์คํธ ์ ์ ํจ์"""
|
79 |
-
sentences = [s.strip() for s in text.split('.') if s.strip()]
|
80 |
-
unique_sentences = []
|
81 |
-
seen = set()
|
82 |
-
|
83 |
-
for sentence in sentences:
|
84 |
-
normalized = ' '.join(sentence.lower().split())
|
85 |
-
if normalized not in seen:
|
86 |
-
seen.add(normalized)
|
87 |
-
unique_sentences.append(sentence)
|
88 |
-
|
89 |
-
cleaned_text = '. '.join(unique_sentences)
|
90 |
-
if cleaned_text and not cleaned_text.endswith('.'):
|
91 |
-
cleaned_text += '.'
|
92 |
-
|
93 |
-
return cleaned_text
|
94 |
-
|
95 |
-
def remove_duplicates(text: str) -> str:
|
96 |
-
"""์ค๋ณต ๋ฌธ์ฅ ์ ๊ฑฐ ํจ์"""
|
97 |
-
sentences = text.split('.')
|
98 |
-
unique_sentences = []
|
99 |
-
seen = set()
|
100 |
-
|
101 |
-
for sentence in sentences:
|
102 |
-
sentence = sentence.strip()
|
103 |
-
if sentence and sentence not in seen:
|
104 |
-
seen.add(sentence)
|
105 |
-
unique_sentences.append(sentence)
|
106 |
-
|
107 |
-
return '. '.join(unique_sentences)
|
108 |
-
|
109 |
-
def upload_csv(file_path: str) -> Tuple[str, str]:
|
110 |
-
try:
|
111 |
-
df = pd.read_csv(file_path, sep=',')
|
112 |
-
required_columns = {'id', 'text', 'label', 'metadata'}
|
113 |
-
available_columns = set(df.columns)
|
114 |
-
missing_columns = required_columns - available_columns
|
115 |
-
if missing_columns:
|
116 |
-
return f"CSV ํ์ผ์ ๋ค์ ํ์ ์ปฌ๋ผ์ด ๋๋ฝ๋์์ต๋๋ค: {', '.join(missing_columns)}", ""
|
117 |
-
|
118 |
-
df.drop_duplicates(inplace=True)
|
119 |
-
df.fillna('', inplace=True)
|
120 |
-
df = df.astype({'id': 'int32', 'text': 'string', 'label': 'category', 'metadata': 'string'})
|
121 |
-
|
122 |
-
parquet_filename = os.path.splitext(os.path.basename(file_path))[0] + '.parquet'
|
123 |
-
df.to_parquet(parquet_filename, engine='pyarrow', compression='snappy')
|
124 |
-
return f"{parquet_filename} ํ์ผ์ด ์ฑ๊ณต์ ์ผ๋ก ์
๋ก๋๋๊ณ ๋ณํ๋์์ต๋๋ค.", parquet_filename
|
125 |
-
except Exception as e:
|
126 |
-
return f"CSV ํ์ผ ์
๋ก๋ ๋ฐ ๋ณํ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", ""
|
127 |
-
|
128 |
-
def upload_parquet(file_path: str) -> Tuple[str, str, str]:
|
129 |
-
try:
|
130 |
-
df = pd.read_parquet(file_path, engine='pyarrow')
|
131 |
-
|
132 |
-
data_info = {
|
133 |
-
"์ด ๋ ์ฝ๋ ์": len(df),
|
134 |
-
"์ปฌ๋ผ ๋ชฉ๋ก": list(df.columns),
|
135 |
-
"๋ฐ์ดํฐ ํ์
": df.dtypes.to_dict(),
|
136 |
-
"๊ฒฐ์ธก์น ์ ๋ณด": df.isnull().sum().to_dict()
|
137 |
-
}
|
138 |
-
|
139 |
-
summary = []
|
140 |
-
summary.append(f"### ๋ฐ์ดํฐ์
๊ธฐ๋ณธ ์ ๋ณด:")
|
141 |
-
summary.append(f"- ์ด ๋ ์ฝ๋ ์: {data_info['์ด ๋ ์ฝ๋ ์']}")
|
142 |
-
summary.append(f"- ์ปฌ๋ผ ๋ชฉ๋ก: {', '.join(data_info['์ปฌ๋ผ ๋ชฉ๋ก'])}")
|
143 |
-
|
144 |
-
summary.append("\n### ์ปฌ๋ผ๋ณ ์ ๋ณด:")
|
145 |
-
for col in df.columns:
|
146 |
-
if df[col].dtype in ['int64', 'float64']:
|
147 |
-
stats = df[col].describe()
|
148 |
-
summary.append(f"\n{col} (์์นํ):")
|
149 |
-
summary.append(f"- ํ๊ท : {stats['mean']:.2f}")
|
150 |
-
summary.append(f"- ์ต์: {stats['min']}")
|
151 |
-
summary.append(f"- ์ต๋: {stats['max']}")
|
152 |
-
elif df[col].dtype == 'object' or df[col].dtype == 'string':
|
153 |
-
unique_count = df[col].nunique()
|
154 |
-
summary.append(f"\n{col} (ํ
์คํธ):")
|
155 |
-
summary.append(f"- ๊ณ ์ ๊ฐ ์: {unique_count}")
|
156 |
-
if unique_count < 10:
|
157 |
-
value_counts = df[col].value_counts().head(5)
|
158 |
-
summary.append("- ์์ 5๊ฐ ๊ฐ:")
|
159 |
-
for val, count in value_counts.items():
|
160 |
-
summary.append(f" โข {val}: {count}๊ฐ")
|
161 |
-
|
162 |
-
preview = df.head(10).to_markdown(index=False)
|
163 |
-
summary.append("\n### ๋ฐ์ดํฐ ๋ฏธ๋ฆฌ๋ณด๊ธฐ:")
|
164 |
-
summary.append(preview)
|
165 |
-
|
166 |
-
parquet_content = "\n".join(summary)
|
167 |
-
parquet_json = df.to_json(orient='records', force_ascii=False)
|
168 |
-
|
169 |
-
return "Parquet ํ์ผ์ด ์ฑ๊ณต์ ์ผ๋ก ์
๋ก๋๋์์ต๋๋ค.", parquet_content, parquet_json
|
170 |
-
except Exception as e:
|
171 |
-
return f"Parquet ํ์ผ ์
๋ก๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", "", ""
|
172 |
-
|
173 |
-
def text_to_parquet(text: str) -> Tuple[str, str, str]:
|
174 |
-
try:
|
175 |
-
lines = [line.strip() for line in text.split('\n') if line.strip()]
|
176 |
-
data = []
|
177 |
-
|
178 |
-
for line in lines:
|
179 |
-
try:
|
180 |
-
import re
|
181 |
-
pattern = r'(\d+),([^,]+),([^,]+),(.+)'
|
182 |
-
match = re.match(pattern, line)
|
183 |
-
|
184 |
-
if match:
|
185 |
-
id_val, text_val, label_val, metadata_val = match.groups()
|
186 |
-
text_val = text_val.strip().strip('"')
|
187 |
-
label_val = label_val.strip().strip('"')
|
188 |
-
metadata_val = metadata_val.strip().strip('"')
|
189 |
-
|
190 |
-
data.append({
|
191 |
-
'id': int(id_val),
|
192 |
-
'text': text_val,
|
193 |
-
'label': label_val,
|
194 |
-
'metadata': metadata_val
|
195 |
-
})
|
196 |
-
except Exception as e:
|
197 |
-
print(f"๋ผ์ธ ํ์ฑ ์ค๋ฅ: {line}\n{str(e)}")
|
198 |
-
continue
|
199 |
-
|
200 |
-
if not data:
|
201 |
-
return "๋ณํํ ๋ฐ์ดํฐ๊ฐ ์์ต๋๋ค.", "", ""
|
202 |
-
|
203 |
-
df = pd.DataFrame(data)
|
204 |
-
df = df.astype({
|
205 |
-
'id': 'int32',
|
206 |
-
'text': 'string',
|
207 |
-
'label': 'string',
|
208 |
-
'metadata': 'string'
|
209 |
-
})
|
210 |
-
|
211 |
-
parquet_filename = 'text_to_parquet.parquet'
|
212 |
-
df.to_parquet(parquet_filename, engine='pyarrow', compression='snappy')
|
213 |
-
preview = df.to_markdown(index=False)
|
214 |
-
|
215 |
-
return (
|
216 |
-
f"{parquet_filename} ํ์ผ์ด ์ฑ๊ณต์ ์ผ๋ก ๋ณํ๋์์ต๋๋ค. ์ด {len(df)}๊ฐ์ ๋ ์ฝ๋๊ฐ ์ฒ๋ฆฌ๋์์ต๋๋ค.",
|
217 |
-
preview,
|
218 |
-
parquet_filename
|
219 |
-
)
|
220 |
-
|
221 |
-
except Exception as e:
|
222 |
-
error_message = f"ํ
์คํธ ๋ณํ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
223 |
-
print(f"{error_message}\n{traceback.format_exc()}")
|
224 |
-
return error_message, "", ""
|
225 |
-
|
226 |
-
def respond(message: str, history: List[Dict[str, str]], system_message: str = "", max_tokens: int = 4000, temperature: float = 0.5, top_p: float = 0.9, parquet_data: str = None, api_key: str = None) -> str:
|
227 |
-
if not api_key:
|
228 |
-
yield "โ ๏ธ API Key๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ์๋น์ค ์ด์ฉ์ ์ํด API Key๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
|
229 |
-
return
|
230 |
-
|
231 |
-
# OpenAI ํด๋ผ์ด์ธํธ ์ด๊ธฐํ
|
232 |
-
client = OpenAI(api_key=api_key)
|
233 |
-
|
234 |
-
system_prefix = """๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ ๊ฒ. ๋๋ ์
๋ก๋๋ ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ง๋ฌธ์ ๋ต๋ณํ๋ ์ญํ ์ ํ๋ค.
|
235 |
-
|
236 |
-
์ฃผ์ ์ง์นจ:
|
237 |
-
1. ์ง๋ฌธ๊ณผ ์ง์ ๊ด๋ จ๋ ๋ด์ฉ๋ง ๊ฐ๋จ๋ช
๋ฃํ๊ฒ ๋ต๋ณํ ๊ฒ
|
238 |
-
2. ์ด์ ๋ต๋ณ๊ณผ ์ค๋ณต๋๋ ๋ด์ฉ์ ์ ์ธํ ๊ฒ
|
239 |
-
3. ๋ถํ์ํ ์์๋ ๋ถ์ฐ ์ค๋ช
์ ํ์ง ๋ง ๊ฒ
|
240 |
-
4. ๋์ผํ ๋ด์ฉ์ ๋ค๋ฅธ ํํ์ผ๋ก ๋ฐ๋ณตํ์ง ๋ง ๊ฒ
|
241 |
-
5. ํต์ฌ ์ ๋ณด๋ง ์ ๋ฌํ ๊ฒ
|
242 |
-
"""
|
243 |
-
|
244 |
-
if parquet_data:
|
245 |
-
try:
|
246 |
-
df = pd.read_json(io.StringIO(parquet_data))
|
247 |
-
data_summary = df.describe(include='all').to_string()
|
248 |
-
system_prefix += f"\n\n๋ฐ์ดํฐ ์์ฝ:\n{data_summary}"
|
249 |
-
except Exception as e:
|
250 |
-
print(f"๋ฐ์ดํฐ ๋ก๋ ์ค๋ฅ: {str(e)}")
|
251 |
-
|
252 |
-
messages = [{"role": "system", "content": system_prefix}]
|
253 |
-
recent_history = history[-3:] if history else []
|
254 |
-
for chat in recent_history:
|
255 |
-
messages.append({"role": chat["role"], "content": chat["content"]})
|
256 |
-
|
257 |
-
messages.append({"role": "user", "content": message})
|
258 |
-
|
259 |
-
try:
|
260 |
-
response = client.chat.completions.create(
|
261 |
-
model="gpt-4o-mini",
|
262 |
-
messages=messages,
|
263 |
-
max_tokens=max_tokens,
|
264 |
-
temperature=temperature,
|
265 |
-
top_p=top_p,
|
266 |
-
stream=True
|
267 |
-
)
|
268 |
-
|
269 |
-
full_response = ""
|
270 |
-
for chunk in response:
|
271 |
-
if chunk.choices[0].delta.content:
|
272 |
-
full_response += chunk.choices[0].delta.content
|
273 |
-
yield clean_response(full_response)
|
274 |
-
|
275 |
-
except Exception as e:
|
276 |
-
error_message = f"์๋ต ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
277 |
-
print(f"{error_message}\n{traceback.format_exc()}")
|
278 |
-
yield error_message
|
279 |
-
|
280 |
-
def preprocess_text_with_llm(input_text: str, api_key: str = None) -> str:
|
281 |
-
if not api_key:
|
282 |
-
return "โ ๏ธ API Key๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ์๋น์ค ์ด์ฉ์ ์ํด API Key๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."
|
283 |
-
|
284 |
-
# OpenAI ํด๋ผ์ด์ธํธ ์ด๊ธฐํ
|
285 |
-
client = OpenAI(api_key=api_key)
|
286 |
-
|
287 |
-
system_prompt = """๋ฐ๋์ ํ๊ธ(ํ๊ตญ์ด)๋ก ๋ต๋ณํ์์ค. ๋น์ ์ ๋ฐ์ดํฐ ์ ์ฒ๋ฆฌ ์ ๋ฌธ๊ฐ์
๋๋ค. ์
๋ ฅ๋ ํ
์คํธ๋ฅผ CSV ๋ฐ์ดํฐ์
ํ์์ผ๋ก ๋ณํํ์ธ์.
|
288 |
-
|
289 |
-
๊ท์น:
|
290 |
-
1. ์ถ๋ ฅ ํ์: id,text,label,metadata
|
291 |
-
2. id: 1๋ถํฐ ์์ํ๋ ์์ฐจ์ ๋ฒํธ
|
292 |
-
3. text: ์๋ฏธ ์๋ ๋จ์๋ก ๋ถ๋ฆฌ๋ ํ
์คํธ
|
293 |
-
4. label: ํ
์คํธ์ ์ฃผ์ ๋ ์นดํ
๊ณ ๋ฆฌ๋ฅผ ์๋ ๊ธฐ์ค์ผ๋ก ์ ํํ๊ฒ ํ ๊ฐ๋ง ์ ํ
|
294 |
-
- Historical_Figure (์ญ์ฌ์ ์ธ๋ฌผ)
|
295 |
-
- Military_History (๊ตฐ์ฌ ์ญ์ฌ)
|
296 |
-
- Technology (๊ธฐ์ )
|
297 |
-
- Politics (์ ์น)
|
298 |
-
- Culture (๋ฌธํ)
|
299 |
-
5. metadata: ๋ ์ง, ์ถ์ฒ ๋ฑ ์ถ๊ฐ ์ ๋ณด"""
|
300 |
-
|
301 |
-
try:
|
302 |
-
response = client.chat.completions.create(
|
303 |
-
model="gpt-4-0125-preview",
|
304 |
-
messages=[
|
305 |
-
{"role": "system", "content": system_prompt},
|
306 |
-
{"role": "user", "content": input_text}
|
307 |
-
],
|
308 |
-
max_tokens=4000,
|
309 |
-
temperature=0.1,
|
310 |
-
stream=True
|
311 |
-
)
|
312 |
-
|
313 |
-
full_response = ""
|
314 |
-
for chunk in response:
|
315 |
-
if chunk.choices[0].delta.content:
|
316 |
-
full_response += chunk.choices[0].delta.content
|
317 |
-
|
318 |
-
processed_text = clean_response(full_response)
|
319 |
-
|
320 |
-
try:
|
321 |
-
from io import StringIO
|
322 |
-
import csv
|
323 |
-
csv.reader(StringIO(processed_text))
|
324 |
-
return processed_text
|
325 |
-
except csv.Error:
|
326 |
-
return "LLM์ด ์ฌ๋ฐ๋ฅธ CSV ํ์์ ์์ฑํ์ง ๋ชปํ์ต๋๋ค. ๋ค์ ์๋ํด์ฃผ์ธ์."
|
327 |
-
|
328 |
-
except Exception as e:
|
329 |
-
error_message = f"์ ์ฒ๋ฆฌ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}"
|
330 |
-
print(error_message)
|
331 |
-
return error_message
|
332 |
-
|
333 |
-
|
334 |
-
# Gradio Blocks ์ธํฐํ์ด์ค ์ค์
|
335 |
-
with gr.Blocks(css=css) as demo:
|
336 |
-
api_key_state = gr.State("") # API ํค๋ฅผ ์ ์ฅํ State ์ถ๊ฐ
|
337 |
-
|
338 |
-
gr.Markdown("# MyEzRAG: LLM์ด ๋๋ง์ ๋ฐ์ดํฐ๋ก ํ์ตํ ์ฝํ
์ธ ์์ฑ/๋ต๋ณ", elem_id="initial-description")
|
339 |
-
|
340 |
-
# API ํค ์
๋ ฅ ์น์
์ถ๊ฐ
|
341 |
-
with gr.Row(elem_classes="api-key-section"):
|
342 |
-
with gr.Column(scale=3):
|
343 |
-
api_key_input = gr.Textbox(
|
344 |
-
label="OpenAI API Key",
|
345 |
-
placeholder="sk-...",
|
346 |
-
type="password",
|
347 |
-
show_label=True
|
348 |
-
)
|
349 |
-
with gr.Column(scale=1):
|
350 |
-
api_key_button = gr.Button("API Key ์ค์ ", variant="primary")
|
351 |
-
|
352 |
-
# API ํค ์ํ ํ์
|
353 |
-
api_key_status = gr.Markdown("โ ๏ธ API Key๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ์๋น์ค ์ด์ฉ์ ์ํด API Key๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.", elem_classes="api-key-status")
|
354 |
-
|
355 |
-
# API ํค ์ค์ ํจ์
|
356 |
-
def set_api_key(api_key: str):
|
357 |
-
if not api_key.strip():
|
358 |
-
return "โ ๏ธ API Key๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ์๋น์ค ์ด์ฉ์ ์ํด API Key๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.", ""
|
359 |
-
if not api_key.startswith("sk-"):
|
360 |
-
return "โ ์ฌ๋ฐ๋ฅด์ง ์์ API Key ํ์์
๋๋ค. ๋ค์ ํ์ธํด์ฃผ์ธ์.", ""
|
361 |
-
return "โ
API Key๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์ค์ ๋์์ต๋๋ค.", api_key
|
362 |
-
|
363 |
-
# API ํค ์ค์ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
364 |
-
api_key_button.click(
|
365 |
-
set_api_key,
|
366 |
-
inputs=[api_key_input],
|
367 |
-
outputs=[api_key_status, api_key_state]
|
368 |
-
)
|
369 |
-
|
370 |
-
gr.Markdown(
|
371 |
-
"### '์ฌ์ฉ ๋ฐฉ๋ฒ' ํญ์ ํตํด ์์ธํ ์ด์ฉ ๋ฐฉ๋ฒ์ ์ฐธ๊ณ ํ์ธ์.\n"
|
372 |
-
"### Tip) '์์ '๋ฅผ ํตํด ๋ค์ํ ํ์ฉ ๋ฐฉ๋ฒ์ ์ฒดํํ๊ณ ์์ฉํด ๋ณด์ธ์, ๋ฐ์ดํฐ์
์
๋ก๋์ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ 10๊ฑด๋ง ์ถ๋ ฅ",
|
373 |
-
elem_id="initial-description"
|
374 |
-
)
|
375 |
-
|
376 |
-
# ์ฒซ ๋ฒ์งธ ํญ: My ๋ฐ์ดํฐ์
+LLM
|
377 |
-
with gr.Tab("My ๋ฐ์ดํฐ์
+LLM"):
|
378 |
-
gr.Markdown("### LLM๊ณผ ๋ํํ๊ธฐ")
|
379 |
-
chatbot_data_upload = gr.Chatbot(label="์ฑ๋ด", type="messages", elem_id="chatbot-data-upload")
|
380 |
-
msg_data_upload = gr.Textbox(label="๋ฉ์์ง ์
๋ ฅ", placeholder="์ฌ๊ธฐ์ ๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...")
|
381 |
-
send_data_upload = gr.Button("์ ์ก")
|
382 |
-
|
383 |
-
with gr.Accordion("์์คํ
ํ๋กฌํํธ ๋ฐ ์ต์
์ค์ ", open=False):
|
384 |
-
system_message = gr.Textbox(label="System Message", value="๋๋ AI ์กฐ์ธ์ ์ญํ ์ด๋ค.")
|
385 |
-
max_tokens = gr.Slider(minimum=1, maximum=8000, value=1000, label="Max Tokens")
|
386 |
-
temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature")
|
387 |
-
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
|
388 |
-
|
389 |
-
parquet_data_state = gr.State()
|
390 |
-
|
391 |
-
def handle_message_data_upload(message: str, history: List[Dict[str, str]], system_message: str, max_tokens: int, temperature: float, top_p: float, parquet_data: str, api_key: str):
|
392 |
-
if not api_key:
|
393 |
-
history = history or []
|
394 |
-
history.append({"role": "assistant", "content": "โ ๏ธ API Key๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. ์๋น์ค ์ด์ฉ์ ์ํด API Key๋ฅผ ์
๋ ฅํด์ฃผ์ธ์."})
|
395 |
-
yield history, ""
|
396 |
-
return
|
397 |
-
|
398 |
-
history = history or []
|
399 |
-
recent_questions = [chat['content'].strip().lower() for chat in history[-3:] if chat['role'] == 'user']
|
400 |
-
if message.strip().lower() in recent_questions:
|
401 |
-
yield history + [{"role": "assistant", "content": "๋์ผํ ์ง๋ฌธ์ด ์ต๊ทผ์ ์์์ต๋๋ค. ๋ค๋ฅธ ์ง๋ฌธ์ ํด์ฃผ์ธ์."}], ""
|
402 |
-
return
|
403 |
-
|
404 |
-
try:
|
405 |
-
history.append({"role": "user", "content": message})
|
406 |
-
response_gen = respond(
|
407 |
-
message,
|
408 |
-
history,
|
409 |
-
system_message,
|
410 |
-
max_tokens,
|
411 |
-
temperature=0.3,
|
412 |
-
top_p=top_p,
|
413 |
-
parquet_data=parquet_data,
|
414 |
-
api_key=api_key
|
415 |
-
)
|
416 |
-
|
417 |
-
partial_response = ""
|
418 |
-
for partial in response_gen:
|
419 |
-
partial_response = partial
|
420 |
-
display_history = history + [{"role": "assistant", "content": partial_response}]
|
421 |
-
yield display_history, ""
|
422 |
-
|
423 |
-
history.append({"role": "assistant", "content": partial_response})
|
424 |
-
except Exception as e:
|
425 |
-
response = f"์ค๋ฅ ๋ฐ์: {str(e)}"
|
426 |
-
history.append({"role": "assistant", "content": response})
|
427 |
-
yield history, ""
|
428 |
-
|
429 |
-
send_data_upload.click(
|
430 |
-
handle_message_data_upload,
|
431 |
-
inputs=[
|
432 |
-
msg_data_upload,
|
433 |
-
chatbot_data_upload,
|
434 |
-
system_message,
|
435 |
-
max_tokens,
|
436 |
-
temperature,
|
437 |
-
top_p,
|
438 |
-
parquet_data_state,
|
439 |
-
api_key_state,
|
440 |
-
],
|
441 |
-
outputs=[chatbot_data_upload, msg_data_upload],
|
442 |
-
queue=True
|
443 |
-
)
|
444 |
-
|
445 |
-
# ์์ ์ถ๊ฐ
|
446 |
-
with gr.Accordion("์์ ", open=False):
|
447 |
-
gr.Examples(
|
448 |
-
examples=[
|
449 |
-
["์
๋ก๋๋ ๋ฐ์ดํฐ์
์ ๋ํด ์์ฝ ์ค๋ช
ํ๋ผ."],
|
450 |
-
["์
๋ก๋๋ ๋ฐ์ดํฐ์
ํ์ผ์ ํ์ต ๋ฐ์ดํฐ๋ก ํ์ฉํ์ฌ, ๋ณธ ์๋น์ค๋ฅผ SEO ์ต์ ํํ์ฌ ๋ธ๋ก๊ทธ ํฌ์คํธ(๊ฐ์, ๋ฐฐ๊ฒฝ ๋ฐ ํ์์ฑ, ๊ธฐ์กด ์ ์ฌ ์ ํ/์๋น์ค์ ๋น๊ตํ์ฌ ํน์ฅ์ , ํ์ฉ์ฒ, ๊ฐ์น, ๊ธฐ๋ํจ๊ณผ, ๊ฒฐ๋ก ์ ํฌํจ)๋ก 4000 ํ ํฐ ์ด์ ์์ฑํ๋ผ"],
|
451 |
-
["์
๋ก๋๋ ๋ฐ์ดํฐ์
ํ์ผ์ ํ์ต ๋ฐ์ดํฐ๋ก ํ์ฉํ์ฌ, ์ฌ์ฉ ๋ฐฉ๋ฒ๊ณผ ์ฐจ๋ณ์ , ํน์ง, ๊ฐ์ ์ ์ค์ฌ์ผ๋ก 4000 ํ ํฐ ์ด์ ์ ํ๋ธ ์์ ์คํฌ๋ฆฝํธ ํํ๋ก ์์ฑํ๋ผ"],
|
452 |
-
["์
๋ก๋๋ ๋ฐ์ดํฐ์
ํ์ผ์ ํ์ต ๋ฐ์ดํฐ๋ก ํ์ฉํ์ฌ, ์ ํ ์์ธ ํ์ด์ง ํ์์ ๋ด์ฉ์ 4000 ํ ํฐ ์ด์ ์์ธํ ์ค๋ช
ํ๋ผ"],
|
453 |
-
["์
๋ก๋๋ ๋ฐ์ดํฐ์
ํ์ผ์ ํ์ต ๋ฐ์ดํฐ๋ก ํ์ฉํ์ฌ, FAQ 20๊ฑด์ ์์ธํ๊ฒ ์์ฑํ๋ผ. 4000ํ ํฐ ์ด์ ์ฌ์ฉํ๋ผ."],
|
454 |
-
["์
๋ก๋๋ ๋ฐ์ดํฐ์
ํ์ผ์ ํ์ต ๋ฐ์ดํฐ๋ก ํ์ฉํ์ฌ, ํนํ ์ถ์์ ํ์ฉํ ๊ธฐ์ ๋ฐ ๋น์ฆ๋์ค ๋ชจ๋ธ ์ธก๋ฉด์ ํฌํจํ์ฌ ํนํ ์ถ์์ ๊ตฌ์ฑ์ ๋ง๊ฒ ํ์ ์ ์ธ ์ฐฝ์ ๋ฐ๋ช
๋ด์ฉ์ ์ค์ฌ์ผ๋ก 4000 ํ ํฐ ์ด์ ์์ฑํ๋ผ."],
|
455 |
-
],
|
456 |
-
inputs=msg_data_upload,
|
457 |
-
label="์์ ์ ํ",
|
458 |
-
)
|
459 |
-
|
460 |
-
# Parquet ํ์ผ ์
๋ก๋
|
461 |
-
gr.Markdown("### Parquet ํ์ผ ์
๋ก๋")
|
462 |
-
with gr.Row():
|
463 |
-
with gr.Column():
|
464 |
-
parquet_upload = gr.File(
|
465 |
-
label="Parquet ํ์ผ ์
๋ก๋", type="filepath", elem_id="parquet-upload-area"
|
466 |
-
)
|
467 |
-
parquet_upload_button = gr.Button("์
๋ก๋")
|
468 |
-
parquet_upload_status = gr.Textbox(label="์
๋ก๋ ์ํ", interactive=False)
|
469 |
-
parquet_preview_chat = gr.Markdown(label="Parquet ํ์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
|
470 |
-
|
471 |
-
def handle_parquet_upload(file_path: str):
|
472 |
-
message, parquet_content, parquet_json = upload_parquet(file_path)
|
473 |
-
if parquet_json:
|
474 |
-
return message, parquet_content, parquet_json
|
475 |
-
else:
|
476 |
-
return message, "", ""
|
477 |
-
|
478 |
-
parquet_upload_button.click(
|
479 |
-
handle_parquet_upload,
|
480 |
-
inputs=parquet_upload,
|
481 |
-
outputs=[parquet_upload_status, parquet_preview_chat, parquet_data_state]
|
482 |
-
)
|
483 |
-
|
484 |
-
# ๋ ๋ฒ์งธ ํญ: CSV to My ๋ฐ์ดํฐ์
|
485 |
-
with gr.Tab("CSV to My ๋ฐ์ดํฐ์
"):
|
486 |
-
gr.Markdown("### CSV ํ์ผ ์
๋ก๋ ๋ฐ Parquet ๋ณํ")
|
487 |
-
with gr.Row():
|
488 |
-
with gr.Column():
|
489 |
-
csv_file = gr.File(label="CSV ํ์ผ ์
๋ก๋", type="filepath")
|
490 |
-
upload_button = gr.Button("์
๋ก๋ ๋ฐ ๋ณํ")
|
491 |
-
upload_status = gr.Textbox(label="์
๋ก๋ ์ํ", interactive=False)
|
492 |
-
parquet_preview = gr.Markdown(label="Parquet ํ์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
|
493 |
-
download_button = gr.File(label="Parquet ํ์ผ ๋ค์ด๋ก๋", interactive=False)
|
494 |
-
|
495 |
-
def handle_csv_upload(file_path: str):
|
496 |
-
message, parquet_filename = upload_csv(file_path)
|
497 |
-
if parquet_filename:
|
498 |
-
parquet_content = load_parquet(parquet_filename)
|
499 |
-
return message, parquet_content, parquet_filename
|
500 |
-
else:
|
501 |
-
return message, "", None
|
502 |
-
|
503 |
-
upload_button.click(
|
504 |
-
handle_csv_upload,
|
505 |
-
inputs=csv_file,
|
506 |
-
outputs=[upload_status, parquet_preview, download_button]
|
507 |
-
)
|
508 |
-
|
509 |
-
# ์ธ ๋ฒ์งธ ํญ: Text to My ๋ฐ์ดํฐ์
|
510 |
-
with gr.Tab("Text to My ๋ฐ์ดํฐ์
"):
|
511 |
-
gr.Markdown("### ํ
์คํธ๋ฅผ ์
๋ ฅํ๋ฉด CSV๋ก ๋ณํ ํ Parquet์ผ๋ก ์๋ ์ ํ๋ฉ๋๋ค.")
|
512 |
-
with gr.Row():
|
513 |
-
with gr.Column():
|
514 |
-
text_input = gr.Textbox(
|
515 |
-
label="ํ
์คํธ ์
๋ ฅ (๊ฐ ํ์ `id,text,label,metadata` ํ์์ผ๋ก ์
๋ ฅ)",
|
516 |
-
lines=10,
|
517 |
-
placeholder='์: 1,"์ด์์ ","์ฅ๊ตฐ","๊ฑฐ๋ถ์ "\n2,"์๊ท ","์ฅ๊ตฐ","๋ชจํจ"\n3,"์ ์กฐ","์","์๊ธฐ"\n4,"๋์ํ ๋ฏธ ํ๋ฐ์์","์","์นจ๋ต"'
|
518 |
-
)
|
519 |
-
convert_button = gr.Button("๋ณํ ๋ฐ ๋ค์ด๋ก๋")
|
520 |
-
convert_status = gr.Textbox(label="๋ณํ ์ํ", interactive=False)
|
521 |
-
parquet_preview_convert = gr.Markdown(label="Parquet ํ์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
|
522 |
-
download_parquet_convert = gr.File(label="Parquet ํ์ผ ๋ค์ด๋ก๋", interactive=False)
|
523 |
-
|
524 |
-
def handle_text_to_parquet(text: str):
|
525 |
-
message, parquet_content, parquet_filename = text_to_parquet(text)
|
526 |
-
if parquet_filename:
|
527 |
-
return message, parquet_content, parquet_filename
|
528 |
-
else:
|
529 |
-
return message, "", None
|
530 |
-
|
531 |
-
convert_button.click(
|
532 |
-
handle_text_to_parquet,
|
533 |
-
inputs=text_input,
|
534 |
-
outputs=[convert_status, parquet_preview_convert, download_parquet_convert]
|
535 |
-
)
|
536 |
-
|
537 |
-
# ๋ค ๋ฒ์งธ ํญ: Text Preprocessing with LLM
|
538 |
-
with gr.Tab("Text Preprocessing with LLM"):
|
539 |
-
gr.Markdown("### ํ
์คํธ๋ฅผ ์
๋ ฅํ๋ฉด LLM์ด ๋ฐ์ดํฐ์
ํ์์ ๋ง๊ฒ ์ ์ฒ๋ฆฌํ์ฌ ์ถ๋ ฅํฉ๋๋ค.")
|
540 |
-
with gr.Row():
|
541 |
-
with gr.Column():
|
542 |
-
raw_text_input = gr.Textbox(
|
543 |
-
label="ํ
์คํธ ์
๋ ฅ",
|
544 |
-
lines=15,
|
545 |
-
placeholder="์ฌ๊ธฐ์ ์ ์ฒ๋ฆฌํ ํ
์คํธ๋ฅผ ์
๋ ฅํ์ธ์..."
|
546 |
-
)
|
547 |
-
|
548 |
-
with gr.Row():
|
549 |
-
preprocess_button = gr.Button("์ ์ฒ๋ฆฌ ์คํ", variant="primary")
|
550 |
-
clear_button = gr.Button("์ด๊ธฐํ")
|
551 |
-
|
552 |
-
preprocess_status = gr.Textbox(
|
553 |
-
label="์ ์ฒ๋ฆฌ ์ํ",
|
554 |
-
interactive=False,
|
555 |
-
value="๋๊ธฐ ์ค..."
|
556 |
-
)
|
557 |
-
|
558 |
-
processed_text_output = gr.Textbox(
|
559 |
-
label="์ ์ฒ๋ฆฌ๋ ๋ฐ์ดํฐ์
์ถ๋ ฅ",
|
560 |
-
lines=15,
|
561 |
-
interactive=False
|
562 |
-
)
|
563 |
-
|
564 |
-
convert_to_parquet_button = gr.Button("Parquet์ผ๋ก ๋ณํ")
|
565 |
-
download_parquet = gr.File(label="๋ณํ๋ Parquet ํ์ผ ๋ค์ด๋ก๋")
|
566 |
-
|
567 |
-
def handle_text_preprocessing(input_text: str, api_key: str):
|
568 |
-
if not api_key:
|
569 |
-
yield "โ ๏ธ API Key๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.", ""
|
570 |
-
return
|
571 |
-
|
572 |
-
if not input_text.strip():
|
573 |
-
yield "์
๋ ฅ ํ
์คํธ๊ฐ ์์ต๋๋ค.", ""
|
574 |
-
return
|
575 |
-
|
576 |
-
try:
|
577 |
-
yield "์ ์ฒ๋ฆฌ๋ฅผ ์์ํฉ๋๋ค...", ""
|
578 |
-
processed_text = preprocess_text_with_llm(input_text, api_key)
|
579 |
-
|
580 |
-
if processed_text:
|
581 |
-
yield "์ ์ฒ๋ฆฌ๊ฐ ์๋ฃ๋์์ต๋๋ค.", processed_text
|
582 |
-
else:
|
583 |
-
yield "์ ์ฒ๋ฆฌ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค.", ""
|
584 |
-
|
585 |
-
except Exception as e:
|
586 |
-
yield f"์ฒ๋ฆฌ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", ""
|
587 |
-
|
588 |
-
def clear_inputs():
|
589 |
-
return "", "๋๏ฟฝ๏ฟฝ ์ค...", ""
|
590 |
-
|
591 |
-
def convert_to_parquet_file(processed_text: str):
|
592 |
-
if not processed_text.strip():
|
593 |
-
return "๋ณํํ ํ
์คํธ๊ฐ ์์ต๋๋ค.", None
|
594 |
-
|
595 |
-
try:
|
596 |
-
message, parquet_content, parquet_filename = text_to_parquet(processed_text)
|
597 |
-
if parquet_filename:
|
598 |
-
return message, parquet_filename
|
599 |
-
return message, None
|
600 |
-
except Exception as e:
|
601 |
-
return f"Parquet ๋ณํ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}", None
|
602 |
-
|
603 |
-
preprocess_button.click(
|
604 |
-
handle_text_preprocessing,
|
605 |
-
inputs=[raw_text_input, api_key_state],
|
606 |
-
outputs=[preprocess_status, processed_text_output],
|
607 |
-
queue=True
|
608 |
-
)
|
609 |
-
|
610 |
-
clear_button.click(
|
611 |
-
clear_inputs,
|
612 |
-
outputs=[raw_text_input, preprocess_status, processed_text_output]
|
613 |
-
)
|
614 |
-
|
615 |
-
convert_to_parquet_button.click(
|
616 |
-
convert_to_parquet_file,
|
617 |
-
inputs=[processed_text_output],
|
618 |
-
outputs=[preprocess_status, download_parquet]
|
619 |
-
)
|
620 |
-
|
621 |
-
with gr.Accordion("์์ ํ
์คํธ", open=False):
|
622 |
-
gr.Examples(
|
623 |
-
examples=[
|
624 |
-
["์ด์์ ์ ์กฐ์ ์ค๊ธฐ์ ๋ฌด์ ์ด๋ค. ๊ทธ๋ ์์ง์๋ ๋น์ ํด๊ตฐ์ ์ด๋์๋ค. ๊ฑฐ๋ถ์ ์ ๋ง๋ค์ด ์๊ตฐ๊ณผ ์ธ์ ๋ค."],
|
625 |
-
["์ธ๊ณต์ง๋ฅ์ ์ปดํจํฐ ๊ณผํ์ ํ ๋ถ์ผ์ด๋ค. ๊ธฐ๊ณํ์ต์ ์ธ๊ณต์ง๋ฅ์ ํ์ ๋ถ์ผ์ด๋ค. ๋ฅ๋ฌ๋์ ๊ธฐ๊ณํ์ต์ ํ ๋ฐฉ๋ฒ์ด๋ค."]
|
626 |
-
],
|
627 |
-
inputs=raw_text_input,
|
628 |
-
label="์์ ์ ํ"
|
629 |
-
)
|
630 |
-
|
631 |
-
# ์ฌ์ฉ ๋ฐฉ๋ฒ ํญ
|
632 |
-
with gr.Tab("๐ ์ฌ์ฉ ๋ฐฉ๋ฒ"):
|
633 |
-
gr.Markdown("""
|
634 |
-
# MyEzRAG ์ฌ์ฉ ๊ฐ์ด๋
|
635 |
-
|
636 |
-
## ๐ API Key ์ค์
|
637 |
-
1. OpenAI API Key๋ฅผ ์๋จ ์
๋ ฅ์ฐฝ์ ์
๋ ฅ
|
638 |
-
2. 'API Key ์ค์ ' ๋ฒํผ ํด๋ฆญ
|
639 |
-
3. ์ค์ ์ฑ๊ณต ๋ฉ์์ง ํ์ธ
|
640 |
-
|
641 |
-
## 1๏ธโฃ My ๋ฐ์ดํฐ์
+LLM ํญ
|
642 |
-
### ๊ธฐ๋ฅ
|
643 |
-
- ์
๋ก๋๋ Parquet ๋ฐ์ดํฐ์
์ ๊ธฐ๋ฐ์ผ๋ก LLM๊ณผ ๋ํ
|
644 |
-
- ๋ฐ์ดํฐ์
์ ๋ด์ฉ์ ํ์ฉํ ์ฝํ
์ธ ์์ฑ
|
645 |
-
|
646 |
-
### ์ฌ์ฉ ๋ฐฉ๋ฒ
|
647 |
-
1. Parquet ํ์ผ ์
๋ก๋ ์น์
์์ ๋ฐ์ดํฐ์
ํ์ผ์ ์
๋ก๋
|
648 |
-
2. ์ฑํ
์ฐฝ์ ์ํ๋ ์ง๋ฌธ์ด๋ ์์ฒญ์ฌํญ ์
๋ ฅ
|
649 |
-
3. ์์ ๋ฒํผ์ ํ์ฉํ์ฌ ๋ค์ํ ํ์ฉ ์ฌ๋ก ์ฒดํ
|
650 |
-
|
651 |
-
### ํ
|
652 |
-
- ์์คํ
ํ๋กฌํํธ ์ค์ ์ผ๋ก ์๋ต ์คํ์ผ ์กฐ์ ๊ฐ๋ฅ
|
653 |
-
- ์์ธํ ์ง๋ฌธ์ผ์๋ก ๋ ์ ํํ ๋ต๋ณ ์ ๊ณต
|
654 |
-
|
655 |
-
---
|
656 |
-
|
657 |
-
## 2๏ธโฃ CSV to My ๋ฐ์ดํฐ์
ํญ
|
658 |
-
### ๊ธฐ๋ฅ
|
659 |
-
- CSV ํ์ผ์ Parquet ํ์์ผ๋ก ๋ณํ
|
660 |
-
- ๋ฐ์ดํฐ ์ต์ ํ ๋ฐ ์ ์
|
661 |
-
|
662 |
-
### ์ฌ์ฉ ๋ฐฉ๋ฒ
|
663 |
-
1. CSV ํ์ผ ์ค๋น (ํ์ ์ปฌ๋ผ: id, text, label, metadata)
|
664 |
-
2. ํ์ผ ์
๋ก๋ ํ '์
๋ก๋ ๋ฐ ๋ณํ' ๋ฒํผ ํด๋ฆญ
|
665 |
-
3. ๋ณํ๋ Parquet ํ์ผ ๋ค์ด๋ก๋
|
666 |
-
|
667 |
-
### ์ฃผ์์ฌํญ
|
668 |
-
- CSV ํ์ผ์ ๋ฐ๋์ ํ์ ์ปฌ๋ผ์ ํฌํจํด์ผ ํจ
|
669 |
-
- ์ธ์ฝ๋ฉ์ UTF-8 ๊ถ์ฅ
|
670 |
-
|
671 |
-
---
|
672 |
-
|
673 |
-
## 3๏ธโฃ Text to My ๋ฐ์ดํฐ์
ํญ
|
674 |
-
### ๊ธฐ๋ฅ
|
675 |
-
- ํ
์คํธ ํ์์ ๋ฐ์ดํฐ๋ฅผ Parquet์ผ๋ก ๋ณํ
|
676 |
-
- ์๋ ๋ฐ์ดํฐ ์
๋ ฅ ์ง์
|
677 |
-
|
678 |
-
### ์ฌ์ฉ ๋ฐฉ๋ฒ
|
679 |
-
1. ์ง์ ๋ ํ์์ผ๋ก ํ
์คํธ ์
๋ ฅ
|
680 |
-
```
|
681 |
-
1,"์ด์์ ","์ฅ๊ตฐ","๊ฑฐ๋ถ์ "
|
682 |
-
2,"์๊ท ","์ฅ๊ตฐ","๋ชจํจ"
|
683 |
-
```
|
684 |
-
2. '๋ณํ ๋ฐ ๋ค์ด๋ก๋' ๋ฒํผ ํด๋ฆญ
|
685 |
-
3. ๋ณํ๋ ํ์ผ ํ์ธ ๋ฐ ๋ค์ด๋ก๋
|
686 |
-
|
687 |
-
### ์
๋ ฅ ํ์
|
688 |
-
- id: ์์ฐจ์ ๋ฒํธ
|
689 |
-
- text: ์ค์ ํ
์คํธ ๋ด์ฉ
|
690 |
-
- label: ๋ถ๋ฅ ๋ผ๋ฒจ
|
691 |
-
- metadata: ๋ถ๊ฐ ์ ๋ณด
|
692 |
-
|
693 |
-
---
|
694 |
-
|
695 |
-
## 4๏ธโฃ Text Preprocessing with LLM ํญ
|
696 |
-
### ๊ธฐ๋ฅ
|
697 |
-
- LLM์ ํ์ฉํ ์๋ ํ
์คํธ ์ ์ฒ๋ฆฌ
|
698 |
-
- ๊ตฌ์กฐํ๋ ๋ฐ์ดํฐ์
์์ฑ
|
699 |
-
|
700 |
-
### ์ฌ์ฉ ๋ฐฉ๋ฒ
|
701 |
-
1. ์๋ฌธ ํ
์คํธ ์
๋ ฅ
|
702 |
-
2. '์ ์ฒ๋ฆฌ ์คํ' ๋ฒํผ ํด๋ฆญ
|
703 |
-
3. ๊ฒฐ๊ณผ ํ์ธ ํ ํ์์ Parquet ๋ณํ
|
704 |
-
|
705 |
-
### ํน์ง
|
706 |
-
- ์๋ ๋ ์ด๋ธ๋ง
|
707 |
-
- ๋ฌธ์ฅ ๋จ์ ๋ถ๋ฆฌ
|
708 |
-
- ์ค๋ณต ์ ๊ฑฐ
|
709 |
-
- ๋ฐ์ดํฐ ์ ๊ทํ
|
710 |
-
|
711 |
-
## ๐ก ์ผ๋ฐ์ ์ธ ํ
|
712 |
-
- API Key๋ ์์ ํ๊ฒ ๋ณด๊ดํ๊ณ ์ฃผ๊ธฐ์ ์ผ๋ก ๊ฐฑ์
|
713 |
-
- ๊ฐ ํญ์ ์์ ๋ฅผ ์ฐธ๊ณ ํ์ฌ ์ฌ์ฉ๋ฒ ์ตํ๊ธฐ
|
714 |
-
- ๋ฐ์ดํฐ ํ์ง์ด ์ข์์๋ก ๋ ๋์ ๊ฒฐ๊ณผ ์ ๊ณต
|
715 |
-
- ์ค๋ฅ ๋ฐ์ ์ ์
๋ ฅ ๋ฐ์ดํฐ ํ์ ํ์ธ
|
716 |
-
- ๋์ฉ๋ ์ฒ๋ฆฌ ์ ์ ์ ํ ์ฒญํฌ ํฌ๊ธฐ๋ก ๋ถํ ์ฒ๋ฆฌ
|
717 |
-
|
718 |
-
## โ ๏ธ ์ฃผ์์ฌํญ
|
719 |
-
- API Key๋ฅผ ํ์ธ๊ณผ ๊ณต์ ํ์ง ์๊ธฐ
|
720 |
-
- ๋ฏผ๊ฐํ ๊ฐ์ธ์ ๋ณด ํฌํจํ์ง ์๊ธฐ
|
721 |
-
- ๋ฐ์ดํฐ ๋ฐฑ์
๊ถ์ฅ
|
722 |
-
- ๋คํธ์ํฌ ์ํ ํ์ธ
|
723 |
-
- ๋ธ๋ผ์ฐ์ ์บ์ ์ฃผ๊ธฐ์ ์ ๋ฆฌ
|
724 |
-
|
725 |
-
## ๐ ๋ฌธ์ ํด๊ฒฐ
|
726 |
-
- API Key ์ค๋ฅ: ํค ํ์ ๋ฐ ์ ํจ์ฑ ํ์ธ
|
727 |
-
- ์ค๋ฅ ๋ฐ์ ์ ์
๋ ฅ ๋ฐ์ดํฐ ํ์ ํ์ธ
|
728 |
-
- ํ์ผ ์
๋ก๋ ์คํจ ์ ํ์ผ ํฌ๊ธฐ ๋ฐ ํ์ ํ์ธ
|
729 |
-
- ๋ณํ ์คํจ ์ ๋ฐ์ดํฐ ์ธ์ฝ๋ฉ ํ์ธ
|
730 |
-
- ์๋ต์ด ๋๋ฆด ๊ฒฝ์ฐ ๋ฐ์ดํฐ ํฌ๊ธฐ ์กฐ์
|
731 |
-
""")
|
732 |
-
|
733 |
-
gr.Markdown("### [email protected]", elem_id="initial-description")
|
734 |
-
|
735 |
-
if __name__ == "__main__":
|
736 |
-
demo.launch(share=True)
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
exec(os.environ.get('APP'))
|
|
|
|
|
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