Update app.py
Browse files
app.py
CHANGED
@@ -30,54 +30,47 @@ fashion_code = load_code('fashion.cod')
|
|
30 |
uhdimage_code = load_code('uhdimage.cod')
|
31 |
MixGEN_code = load_code('mgen.cod')
|
32 |
|
33 |
-
# μ΄κΈ° Parquet νμΌ λ‘λ (κΈ°μ‘΄ test.parquet)
|
34 |
-
test_parquet_content = load_parquet('test.parquet')
|
35 |
-
|
36 |
def respond(
|
37 |
message: str,
|
38 |
history: List[Dict[str, str]],
|
39 |
system_message: str = "",
|
40 |
-
max_tokens: int =
|
41 |
temperature: float = 0.7,
|
42 |
top_p: float = 0.9,
|
|
|
43 |
) -> str:
|
44 |
# μμ€ν
ν둬ννΈ μ€μ
|
45 |
-
system_prefix = """λ°λμ νκΈλ‘ λ΅λ³ν κ². λλ μ£Όμ΄μ§ μμ€μ½λλ₯Ό κΈ°λ°μΌλ‘ "μλΉμ€ μ¬μ© μ€λͺ
λ° μλ΄, Q&Aλ₯Ό νλ μν μ΄λ€". μμ£Ό μΉμ νκ³ μμΈνκ²
|
46 |
|
47 |
# νΉμ λͺ
λ Ήμ΄ μ²λ¦¬
|
48 |
if message.lower() == "ν¨μ
μ½λ μ€ν":
|
49 |
system_prefix += f"\n\nν¨μ
μ½λ λ΄μ©:\n```python\n{fashion_code}\n```"
|
50 |
-
message = "ν¨μ
κ°μνΌν
μ λν λ΄μ©μ νμ΅νμκ³ , μ€λͺ
ν μ€λΉκ°
|
51 |
elif message.lower() == "uhd μ΄λ―Έμ§ μ½λ μ€ν":
|
52 |
system_prefix += f"\n\nUHD μ΄λ―Έμ§ μ½λ λ΄μ©:\n```python\n{uhdimage_code}\n```"
|
53 |
-
message = "UHD μ΄λ―Έμ§ μμ±μ λν λ΄μ©μ νμ΅νμκ³ , μ€λͺ
ν μ€λΉκ°
|
54 |
elif message.lower() == "mixgen μ½λ μ€ν":
|
55 |
system_prefix += f"\n\nMixGEN μ½λ λ΄μ©:\n```python\n{MixGEN_code}\n```"
|
56 |
-
message = "MixGEN3 μ΄λ―Έμ§ μμ±μ λν λ΄μ©μ νμ΅νμκ³ , μ€λͺ
ν μ€λΉκ°
|
57 |
-
elif message.lower() == "test.parquet μ€ν":
|
58 |
-
# historyμμ parquet_content μ°ΎκΈ°
|
59 |
-
parquet_content = ""
|
60 |
-
for item in history:
|
61 |
-
if item['role'] == 'assistant' and 'test.parquet νμΌ λ΄μ©' in item['content']:
|
62 |
-
try:
|
63 |
-
parquet_content = item['content'].split("```markdown\n")[1].split("\n```")[0]
|
64 |
-
except IndexError:
|
65 |
-
parquet_content = ""
|
66 |
-
break
|
67 |
-
system_prefix += f"\n\ntest.parquet νμΌ λ΄μ©:\n```markdown\n{parquet_content}\n```"
|
68 |
-
message = "test.parquet νμΌμ λν λ΄μ©μ νμ΅νμκ³ , κ΄λ ¨ μ€λͺ
λ° Q&Aλ₯Ό μ§νν μ€λΉκ° λμ΄μλ€. κΆκΈν μ μ΄ μμΌλ©΄ λ¬Όμ΄λ³΄λΌ."
|
69 |
elif message.lower() == "csv μ
λ‘λ":
|
70 |
message = "CSV νμΌμ μ
λ‘λνλ €λ©΄ λ λ²μ§Έ νμ μ¬μ©νμΈμ."
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
# μμ€ν
λ©μμ§μ λν κΈ°λ‘ κ²°ν©
|
73 |
messages = [{"role": "system", "content": system_prefix}]
|
74 |
for chat in history:
|
75 |
messages.append({"role": chat['role'], "content": chat['content']})
|
76 |
messages.append({"role": "user", "content": message})
|
77 |
|
78 |
-
response = ""
|
79 |
try:
|
80 |
# λͺ¨λΈμ λ©μμ§ μ μ‘ λ° μλ΅ λ°κΈ°
|
|
|
81 |
for msg in hf_client.chat_completion(
|
82 |
messages,
|
83 |
max_tokens=max_tokens,
|
@@ -116,14 +109,11 @@ def upload_csv(file_path: str) -> Tuple[str, str]:
|
|
116 |
parquet_filename = os.path.splitext(os.path.basename(file_path))[0] + '.parquet'
|
117 |
df.to_parquet(parquet_filename, engine='pyarrow', compression='snappy')
|
118 |
|
119 |
-
# Parquet νμΌ λ΄μ© 미리보기
|
120 |
-
parquet_content = load_parquet(parquet_filename)
|
121 |
-
|
122 |
return f"{parquet_filename} νμΌμ΄ μ±κ³΅μ μΌλ‘ μ
λ‘λλκ³ λ³νλμμ΅λλ€.", parquet_filename
|
123 |
except Exception as e:
|
124 |
return f"CSV νμΌ μ
λ‘λ λ° λ³ν μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", ""
|
125 |
|
126 |
-
def upload_parquet(file_path: str) -> Tuple[str, str,
|
127 |
try:
|
128 |
# Parquet νμΌ μ½κΈ°
|
129 |
df = pd.read_parquet(file_path, engine='pyarrow')
|
@@ -131,9 +121,12 @@ def upload_parquet(file_path: str) -> Tuple[str, str, Dict]:
|
|
131 |
# MarkdownμΌλ‘ λ³ννμ¬ λ―Έλ¦¬λ³΄κΈ°
|
132 |
parquet_content = df.head(10).to_markdown(index=False)
|
133 |
|
134 |
-
|
|
|
|
|
|
|
135 |
except Exception as e:
|
136 |
-
return f"Parquet νμΌ μ
λ‘λ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", "",
|
137 |
|
138 |
def text_to_parquet(text: str) -> Tuple[str, str, str]:
|
139 |
try:
|
@@ -178,12 +171,34 @@ textarea, input[type="text"] {
|
|
178 |
with gr.Blocks(css=css) as demo:
|
179 |
gr.Markdown("# LLM μλΉμ€ μΈν°νμ΄μ€")
|
180 |
|
181 |
-
# 첫 λ²μ§Έ ν: μ±λ΄
|
182 |
-
with gr.Tab("μ±λ΄"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
gr.Markdown("### LLMκ³Ό λννκΈ°")
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
|
188 |
with gr.Accordion("μμ€ν
ν둬ννΈ λ° μ΅μ
μ€μ ", open=False):
|
189 |
system_message = gr.Textbox(label="System Message", value="λλ AI μ‘°μΈμ μν μ΄λ€.")
|
@@ -191,49 +206,33 @@ with gr.Blocks(css=css) as demo:
|
|
191 |
temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature")
|
192 |
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
|
193 |
|
194 |
-
|
195 |
-
def handle_message(message, history, system_message, max_tokens, temperature, top_p):
|
196 |
history = history or []
|
|
|
197 |
try:
|
198 |
# μλ΅ μμ±
|
199 |
-
response_gen = respond(message, history, system_message, max_tokens, temperature, top_p)
|
200 |
-
|
201 |
for partial in response_gen:
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
|
|
|
|
|
|
206 |
except Exception as e:
|
207 |
response = f"μΆλ‘ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
208 |
-
history.append({"role": "user", "content": message})
|
209 |
history.append({"role": "assistant", "content": response})
|
210 |
-
|
211 |
|
212 |
-
|
213 |
-
|
214 |
-
inputs=[
|
215 |
-
outputs=[
|
|
|
216 |
)
|
217 |
|
218 |
-
# μμ 볡μ
|
219 |
-
with gr.Accordion("μμ ", open=False):
|
220 |
-
gr.Examples(
|
221 |
-
examples=[
|
222 |
-
["ν¨μ
μ½λ μ€ν"],
|
223 |
-
["UHD μ΄λ―Έμ§ μ½λ μ€ν"],
|
224 |
-
["MixGEN μ½λ μ€ν"],
|
225 |
-
["test.parquet μ€ν"],
|
226 |
-
["μμΈν μ¬μ© λ°©λ²μ λ§μΉ νλ©΄μ 보면μ μ€λͺ
νλ―μ΄ 4000 ν ν° μ΄μ μμΈν μ€λͺ
νλΌ"],
|
227 |
-
["FAQ 20건μ μμΈνκ² μμ±νλΌ. 4000ν ν° μ΄μ μ¬μ©νλΌ."],
|
228 |
-
["μ¬μ© λ°©λ²κ³Ό μ°¨λ³μ , νΉμ§, κ°μ μ μ€μ¬μΌλ‘ 4000 ν ν° μ΄μ μ νλΈ μμ μ€ν¬λ¦½νΈ ννλ‘ μμ±νλΌ"],
|
229 |
-
["λ³Έ μλΉμ€λ₯Ό SEO μ΅μ ννμ¬ λΈλ‘κ·Έ ν¬μ€νΈ(λ°°κ²½ λ° νμμ±, κΈ°μ‘΄ μ μ¬ μλΉμ€μ λΉκ΅νμ¬ νΉμ₯μ , νμ©μ², κ°μΉ, κΈ°λν¨κ³Ό, κ²°λ‘ μ ν¬ν¨)λ‘ 4000 ν ν° μ΄μ μμ±νλΌ"],
|
230 |
-
["νΉν μΆμμ νμ©ν κΈ°μ λ° λΉμ¦λμ€λͺ¨λΈ μΈ‘λ©΄μ ν¬ν¨νμ¬ νΉν μΆμμ ꡬμ±μ λ§κ² νμ μ μΈ μ°½μ λ°λͺ
λ΄μ©μ μ€μ¬μΌλ‘ 4000 ν ν° μ΄μ μμ±νλΌ."],
|
231 |
-
["κ³μ μ΄μ΄μ λ΅λ³νλΌ"],
|
232 |
-
],
|
233 |
-
inputs=msg,
|
234 |
-
label="μμ μ ν",
|
235 |
-
)
|
236 |
-
|
237 |
# λ λ²μ§Έ ν: λ°μ΄ν° λ³ν
|
238 |
with gr.Tab("λ°μ΄ν° λ³ν"):
|
239 |
gr.Markdown("### CSV νμΌ μ
λ‘λ λ° Parquet λ³ν")
|
@@ -258,9 +257,6 @@ with gr.Blocks(css=css) as demo:
|
|
258 |
inputs=csv_file,
|
259 |
outputs=[upload_status, parquet_preview, download_button]
|
260 |
)
|
261 |
-
|
262 |
-
gr.Markdown("### κΈ°μ‘΄ Parquet νμΌ")
|
263 |
-
gr.Markdown(f"**test.parquet νμΌ λ΄μ©:**\n```markdown\n{test_parquet_content}\n```")
|
264 |
|
265 |
# μΈ λ²μ§Έ ν: ν
μ€νΈ to csv to parquet λ³ν
|
266 |
with gr.Tab("ν
μ€νΈ to csv to parquet λ³ν"):
|
@@ -290,66 +286,14 @@ with gr.Blocks(css=css) as demo:
|
|
290 |
outputs=[convert_status, parquet_preview_convert, download_parquet_convert]
|
291 |
)
|
292 |
|
293 |
-
# λ€ λ²μ§Έ ν: μ±λ΄ λ°μ΄ν° μ
λ‘λ
|
294 |
-
with gr.Tab("μ±λ΄ λ°μ΄ν° μ
λ‘λ"):
|
295 |
-
gr.Markdown("### Parquet νμΌ μ
λ‘λ λ° μ§λ¬ΈνκΈ°")
|
296 |
-
with gr.Row():
|
297 |
-
with gr.Column():
|
298 |
-
parquet_upload = gr.File(label="Parquet νμΌ μ
λ‘λ", type="filepath")
|
299 |
-
parquet_upload_button = gr.Button("μ
λ‘λ")
|
300 |
-
parquet_upload_status = gr.Textbox(label="μ
λ‘λ μν", interactive=False)
|
301 |
-
parquet_preview_chat = gr.Markdown(label="Parquet νμΌ λ―Έλ¦¬λ³΄κΈ°")
|
302 |
-
parquet_data_state = gr.State()
|
303 |
-
|
304 |
-
def handle_parquet_upload(file_path: str):
|
305 |
-
message, parquet_content, parquet_json = upload_parquet(file_path)
|
306 |
-
if parquet_json:
|
307 |
-
return message, parquet_content, parquet_json
|
308 |
-
else:
|
309 |
-
return message, "", {}
|
310 |
-
|
311 |
-
parquet_upload_button.click(
|
312 |
-
handle_parquet_upload,
|
313 |
-
inputs=parquet_upload,
|
314 |
-
outputs=[parquet_upload_status, parquet_preview_chat, parquet_data_state]
|
315 |
-
)
|
316 |
-
|
317 |
-
gr.Markdown("### LLMκ³Ό λννκΈ°")
|
318 |
-
chatbot_data_upload = gr.Chatbot(label="μ±λ΄ λ°μ΄ν° μ
λ‘λ", type="messages", elem_id="chatbot-data-upload")
|
319 |
-
msg_data_upload = gr.Textbox(label="λ©μμ§ μ
λ ₯", placeholder="μ¬κΈ°μ λ©μμ§λ₯Ό μ
λ ₯νμΈμ...")
|
320 |
-
send_data_upload = gr.Button("μ μ‘")
|
321 |
-
|
322 |
-
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: Dict):
|
323 |
-
history = history or []
|
324 |
-
try:
|
325 |
-
# Parquet λ°μ΄ν°λ₯Ό νμ©ν μ μλ λ‘μ§ μΆκ° κ°λ₯
|
326 |
-
response_gen = respond(message, history, system_message, max_tokens, temperature, top_p)
|
327 |
-
response = ""
|
328 |
-
for partial in response_gen:
|
329 |
-
response = partial
|
330 |
-
# μ¬μ©μμ λ©μμ§μ μ΄μμ€ν΄νΈμ μλ΅μ νμ€ν 리μ μΆκ°
|
331 |
-
history.append({"role": "user", "content": message})
|
332 |
-
history.append({"role": "assistant", "content": response})
|
333 |
-
except Exception as e:
|
334 |
-
response = f"μΆλ‘ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
335 |
-
history.append({"role": "user", "content": message})
|
336 |
-
history.append({"role": "assistant", "content": response})
|
337 |
-
return history, ""
|
338 |
-
|
339 |
-
send_data_upload.click(
|
340 |
-
handle_message_data_upload,
|
341 |
-
inputs=[msg_data_upload, chatbot_data_upload, system_message, max_tokens, temperature, top_p, parquet_data_state],
|
342 |
-
outputs=[chatbot_data_upload, msg_data_upload]
|
343 |
-
)
|
344 |
-
|
345 |
# μ£Όμ μ¬ν
|
346 |
gr.Markdown("## μ£Όμ μ¬ν")
|
347 |
gr.Markdown("""
|
348 |
- **CSV μ
λ‘λ**: CSV νμΌμ μ
λ‘λνλ©΄ μλμΌλ‘ Parquet νμΌλ‘ λ³νλ©λλ€. CSV νμΌμ λ°λμ **μ½€λ§(`,`)**λ‘ κ΅¬λΆλμ΄μΌ ν©λλ€.
|
349 |
- **Parquet 미리보기**: μ
λ‘λλ Parquet νμΌμ 첫 10κ° νμ΄ λ―Έλ¦¬λ³΄κΈ°λ‘ νμλ©λλ€.
|
350 |
-
- **LLMκ³Όμ λν**:
|
351 |
- **Parquet λ€μ΄λ‘λ**: λ³νλ Parquet νμΌμ λ€μ΄λ‘λνλ €λ©΄ λ³νλ νμΌ μμ λ€μ΄λ‘λ λ§ν¬λ₯Ό ν΄λ¦νμΈμ.
|
352 |
-
- **μ±λ΄ λ°μ΄ν° μ
λ‘λ**:
|
353 |
- **ν
μ€νΈ to csv to parquet**: μΈ λ²μ§Έ νμμ ν
μ€νΈλ₯Ό μ
λ ₯νλ©΄ μλμΌλ‘ CSVλ‘ λ³νλκ³ , λ€μ Parquet νμΌλ‘ μ νλμ΄ λ€μ΄λ‘λν μ μμ΅λλ€.
|
354 |
""")
|
355 |
|
@@ -360,3 +304,4 @@ if __name__ == "__main__":
|
|
360 |
|
361 |
|
362 |
|
|
|
|
30 |
uhdimage_code = load_code('uhdimage.cod')
|
31 |
MixGEN_code = load_code('mgen.cod')
|
32 |
|
|
|
|
|
|
|
33 |
def respond(
|
34 |
message: str,
|
35 |
history: List[Dict[str, str]],
|
36 |
system_message: str = "",
|
37 |
+
max_tokens: int = 1000,
|
38 |
temperature: float = 0.7,
|
39 |
top_p: float = 0.9,
|
40 |
+
parquet_data: Dict = None
|
41 |
) -> str:
|
42 |
# μμ€ν
ν둬ννΈ μ€μ
|
43 |
+
system_prefix = """λ°λμ νκΈλ‘ λ΅λ³ν κ². λλ μ£Όμ΄μ§ μμ€μ½λλ₯Ό κΈ°λ°μΌλ‘ "μλΉμ€ μ¬μ© μ€λͺ
λ° μλ΄, Q&Aλ₯Ό νλ μν μ΄λ€". μμ£Ό μΉμ νκ³ μμΈνκ² Markdown νμμΌλ‘ μμ±νλΌ. λλ μ½λλ₯Ό κΈ°λ°μΌλ‘ μ¬μ© μ€λͺ
λ° μ§μ μλ΅μ μ§ννλ©°, μ΄μ©μμκ² λμμ μ£Όμ΄μΌ νλ€. μ΄μ©μκ° κΆκΈν΄ν λ§ν λ΄μ©μ μΉμ νκ² μλ €μ£Όλλ‘ νλΌ. μ½λ μ 체 λ΄μ©μ λν΄μλ 보μμ μ μ§νκ³ , ν€ κ° λ° μλν¬μΈνΈμ ꡬ체μ μΈ λͺ¨λΈμ 곡κ°νμ§ λ§λΌ."""
|
44 |
|
45 |
# νΉμ λͺ
λ Ήμ΄ μ²λ¦¬
|
46 |
if message.lower() == "ν¨μ
μ½λ μ€ν":
|
47 |
system_prefix += f"\n\nν¨μ
μ½λ λ΄μ©:\n```python\n{fashion_code}\n```"
|
48 |
+
message = "ν¨μ
κ°μνΌν
μ λν λ΄μ©μ νμ΅νμκ³ , μ€λͺ
ν μ€λΉκ° λμ΄μμ΅λλ€. μλΉμ€ URL(https://aiqcamp-fash.hf.space)μ ν΅ν΄ ν
μ€νΈν΄λ³΄μΈμ."
|
49 |
elif message.lower() == "uhd μ΄λ―Έμ§ μ½λ μ€ν":
|
50 |
system_prefix += f"\n\nUHD μ΄λ―Έμ§ μ½λ λ΄μ©:\n```python\n{uhdimage_code}\n```"
|
51 |
+
message = "UHD μ΄λ―Έμ§ μμ±μ λν λ΄μ©μ νμ΅νμκ³ , μ€λͺ
ν μ€λΉκ° λμ΄μμ΅λλ€. μλΉμ€ URL(https://openfree-ultpixgen.hf.space)μ ν΅ν΄ ν
μ€νΈν΄λ³΄μΈμ."
|
52 |
elif message.lower() == "mixgen μ½λ μ€ν":
|
53 |
system_prefix += f"\n\nMixGEN μ½λ λ΄μ©:\n```python\n{MixGEN_code}\n```"
|
54 |
+
message = "MixGEN3 μ΄λ―Έμ§ μμ±μ λν λ΄μ©μ νμ΅νμκ³ , μ€λͺ
ν μ€λΉκ° λμ΄μμ΅λλ€. μλΉμ€ URL(https://openfree-mixgen3.hf.space)μ ν΅ν΄ ν
μ€νΈν΄λ³΄μΈμ."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
elif message.lower() == "csv μ
λ‘λ":
|
56 |
message = "CSV νμΌμ μ
λ‘λνλ €λ©΄ λ λ²μ§Έ νμ μ¬μ©νμΈμ."
|
57 |
|
58 |
+
# Parquet λ°μ΄ν° ν¬ν¨
|
59 |
+
if parquet_data:
|
60 |
+
df = pd.read_json(parquet_data)
|
61 |
+
parquet_content = df.head(10).to_markdown(index=False)
|
62 |
+
system_prefix += f"\n\nμ
λ‘λλ Parquet νμΌ λ΄μ©:\n```markdown\n{parquet_content}\n```"
|
63 |
+
message = "μ
λ‘λλ Parquet νμΌμ λν λ΄μ©μ νμ΅νμμ΅λλ€. κ΄λ ¨νμ¬ κΆκΈν μ μ΄ μμΌλ©΄ λ¬Όμ΄λ³΄μΈμ."
|
64 |
+
|
65 |
# μμ€ν
λ©μμ§μ λν κΈ°λ‘ κ²°ν©
|
66 |
messages = [{"role": "system", "content": system_prefix}]
|
67 |
for chat in history:
|
68 |
messages.append({"role": chat['role'], "content": chat['content']})
|
69 |
messages.append({"role": "user", "content": message})
|
70 |
|
|
|
71 |
try:
|
72 |
# λͺ¨λΈμ λ©μμ§ μ μ‘ λ° μλ΅ λ°κΈ°
|
73 |
+
response = ""
|
74 |
for msg in hf_client.chat_completion(
|
75 |
messages,
|
76 |
max_tokens=max_tokens,
|
|
|
109 |
parquet_filename = os.path.splitext(os.path.basename(file_path))[0] + '.parquet'
|
110 |
df.to_parquet(parquet_filename, engine='pyarrow', compression='snappy')
|
111 |
|
|
|
|
|
|
|
112 |
return f"{parquet_filename} νμΌμ΄ μ±κ³΅μ μΌλ‘ μ
λ‘λλκ³ λ³νλμμ΅λλ€.", parquet_filename
|
113 |
except Exception as e:
|
114 |
return f"CSV νμΌ μ
λ‘λ λ° λ³ν μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", ""
|
115 |
|
116 |
+
def upload_parquet(file_path: str) -> Tuple[str, str, str]:
|
117 |
try:
|
118 |
# Parquet νμΌ μ½κΈ°
|
119 |
df = pd.read_parquet(file_path, engine='pyarrow')
|
|
|
121 |
# MarkdownμΌλ‘ λ³ννμ¬ λ―Έλ¦¬λ³΄κΈ°
|
122 |
parquet_content = df.head(10).to_markdown(index=False)
|
123 |
|
124 |
+
# DataFrameμ JSONμΌλ‘ λ³ν
|
125 |
+
parquet_json = df.to_json()
|
126 |
+
|
127 |
+
return "Parquet νμΌμ΄ μ±κ³΅μ μΌλ‘ μ
λ‘λλμμ΅λλ€.", parquet_content, parquet_json
|
128 |
except Exception as e:
|
129 |
+
return f"Parquet νμΌ μ
λ‘λ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", "", ""
|
130 |
|
131 |
def text_to_parquet(text: str) -> Tuple[str, str, str]:
|
132 |
try:
|
|
|
171 |
with gr.Blocks(css=css) as demo:
|
172 |
gr.Markdown("# LLM μλΉμ€ μΈν°νμ΄μ€")
|
173 |
|
174 |
+
# 첫 λ²μ§Έ ν: μ±λ΄ λ°μ΄ν° μ
λ‘λ (μ΄μ λ€ λ²μ§Έ ν)
|
175 |
+
with gr.Tab("μ±λ΄ λ°μ΄ν° μ
λ‘λ"):
|
176 |
+
gr.Markdown("### Parquet νμΌ μ
λ‘λ λ° μ§λ¬ΈνκΈ°")
|
177 |
+
with gr.Row():
|
178 |
+
with gr.Column():
|
179 |
+
parquet_upload = gr.File(label="Parquet νμΌ μ
λ‘λ", type="filepath")
|
180 |
+
parquet_upload_button = gr.Button("μ
λ‘λ")
|
181 |
+
parquet_upload_status = gr.Textbox(label="μ
λ‘λ μν", interactive=False)
|
182 |
+
parquet_preview_chat = gr.Markdown(label="Parquet νμΌ λ―Έλ¦¬λ³΄κΈ°")
|
183 |
+
parquet_data_state = gr.State()
|
184 |
+
|
185 |
+
def handle_parquet_upload(file_path: str):
|
186 |
+
message, parquet_content, parquet_json = upload_parquet(file_path)
|
187 |
+
if parquet_json:
|
188 |
+
return message, parquet_content, parquet_json
|
189 |
+
else:
|
190 |
+
return message, "", ""
|
191 |
+
|
192 |
+
parquet_upload_button.click(
|
193 |
+
handle_parquet_upload,
|
194 |
+
inputs=parquet_upload,
|
195 |
+
outputs=[parquet_upload_status, parquet_preview_chat, parquet_data_state]
|
196 |
+
)
|
197 |
+
|
198 |
gr.Markdown("### LLMκ³Ό λννκΈ°")
|
199 |
+
chatbot_data_upload = gr.Chatbot(label="μ±λ΄", type="messages", elem_id="chatbot-data-upload")
|
200 |
+
msg_data_upload = gr.Textbox(label="λ©μμ§ μ
λ ₯", placeholder="μ¬κΈ°μ λ©μμ§λ₯Ό μ
λ ₯νμΈμ...")
|
201 |
+
send_data_upload = gr.Button("μ μ‘")
|
202 |
|
203 |
with gr.Accordion("μμ€ν
ν둬ννΈ λ° μ΅μ
μ€μ ", open=False):
|
204 |
system_message = gr.Textbox(label="System Message", value="λλ AI μ‘°μΈμ μν μ΄λ€.")
|
|
|
206 |
temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature")
|
207 |
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
|
208 |
|
209 |
+
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):
|
|
|
210 |
history = history or []
|
211 |
+
history.append({"role": "user", "content": message})
|
212 |
try:
|
213 |
# μλ΅ μμ±
|
214 |
+
response_gen = respond(message, history, system_message, max_tokens, temperature, top_p, parquet_data)
|
215 |
+
partial_response = ""
|
216 |
for partial in response_gen:
|
217 |
+
partial_response = partial
|
218 |
+
# μ΄μμ€ν΄νΈμ λ§μ§λ§ λ©μμ§λ₯Ό μ
λ°μ΄νΈνμ¬ μ€νΈλ¦¬λ° ν¨κ³Ό μ 곡
|
219 |
+
if len(history) > 0 and history[-1]['role'] == 'assistant':
|
220 |
+
history[-1]['content'] = partial_response
|
221 |
+
else:
|
222 |
+
history.append({"role": "assistant", "content": partial_response})
|
223 |
+
yield history, ""
|
224 |
except Exception as e:
|
225 |
response = f"μΆλ‘ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
|
|
226 |
history.append({"role": "assistant", "content": response})
|
227 |
+
yield history, ""
|
228 |
|
229 |
+
send_data_upload.click(
|
230 |
+
handle_message_data_upload,
|
231 |
+
inputs=[msg_data_upload, chatbot_data_upload, system_message, max_tokens, temperature, top_p, parquet_data_state],
|
232 |
+
outputs=[chatbot_data_upload, msg_data_upload],
|
233 |
+
queue=True
|
234 |
)
|
235 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
# λ λ²μ§Έ ν: λ°μ΄ν° λ³ν
|
237 |
with gr.Tab("λ°μ΄ν° λ³ν"):
|
238 |
gr.Markdown("### CSV νμΌ μ
λ‘λ λ° Parquet λ³ν")
|
|
|
257 |
inputs=csv_file,
|
258 |
outputs=[upload_status, parquet_preview, download_button]
|
259 |
)
|
|
|
|
|
|
|
260 |
|
261 |
# μΈ λ²μ§Έ ν: ν
μ€νΈ to csv to parquet λ³ν
|
262 |
with gr.Tab("ν
μ€νΈ to csv to parquet λ³ν"):
|
|
|
286 |
outputs=[convert_status, parquet_preview_convert, download_parquet_convert]
|
287 |
)
|
288 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
# μ£Όμ μ¬ν
|
290 |
gr.Markdown("## μ£Όμ μ¬ν")
|
291 |
gr.Markdown("""
|
292 |
- **CSV μ
λ‘λ**: CSV νμΌμ μ
λ‘λνλ©΄ μλμΌλ‘ Parquet νμΌλ‘ λ³νλ©λλ€. CSV νμΌμ λ°λμ **μ½€λ§(`,`)**λ‘ κ΅¬λΆλμ΄μΌ ν©λλ€.
|
293 |
- **Parquet 미리보기**: μ
λ‘λλ Parquet νμΌμ 첫 10κ° νμ΄ λ―Έλ¦¬λ³΄κΈ°λ‘ νμλ©λλ€.
|
294 |
+
- **LLMκ³Όμ λν**: μ
λ‘λλ Parquet νμΌ λ΄μ©μ κΈ°λ°μΌλ‘ LLMμ΄ μλ΅μ μμ±ν©λλ€.
|
295 |
- **Parquet λ€μ΄λ‘λ**: λ³νλ Parquet νμΌμ λ€μ΄λ‘λνλ €λ©΄ λ³νλ νμΌ μμ λ€μ΄λ‘λ λ§ν¬λ₯Ό ν΄λ¦νμΈμ.
|
296 |
+
- **μ±λ΄ λ°μ΄ν° μ
λ‘λ**: 첫 λ²μ§Έ νμμ Parquet νμΌμ μ
λ‘λνλ©΄ ν΄λΉ λ°μ΄ν°λ₯Ό κΈ°λ°μΌλ‘ μ§λ¬Έκ³Ό λ΅λ³μ μ§νν μ μμ΅λλ€.
|
297 |
- **ν
μ€νΈ to csv to parquet**: μΈ λ²μ§Έ νμμ ν
μ€νΈλ₯Ό μ
λ ₯νλ©΄ μλμΌλ‘ CSVλ‘ λ³νλκ³ , λ€μ Parquet νμΌλ‘ μ νλμ΄ λ€μ΄λ‘λν μ μμ΅λλ€.
|
298 |
""")
|
299 |
|
|
|
304 |
|
305 |
|
306 |
|
307 |
+
|