Update app.py
Browse files
app.py
CHANGED
@@ -167,38 +167,45 @@ footer {
|
|
167 |
#chatbot-container .message, #chatbot-data-upload .message {
|
168 |
font-size: 14px;
|
169 |
}
|
|
|
|
|
|
|
|
|
|
|
170 |
"""
|
171 |
|
172 |
# Gradio Blocks μΈν°νμ΄μ€ μ€μ
|
173 |
-
with gr.Blocks(
|
174 |
gr.Markdown("# LLM μλΉμ€ μΈν°νμ΄μ€")
|
175 |
|
176 |
# 첫 λ²μ§Έ ν: μ±λ΄
|
177 |
with gr.Tab("μ±λ΄"):
|
178 |
gr.Markdown("### LLMκ³Ό λννκΈ°")
|
179 |
chatbot = gr.Chatbot(label="μ±λ΄", type="messages", elem_id="chatbot-container")
|
180 |
-
msg = gr.Textbox(label="λ©μμ§ μ
λ ₯", placeholder="μ¬κΈ°μ λ©μμ§λ₯Ό μ
λ ₯νμΈμ...")
|
181 |
send = gr.Button("μ μ‘")
|
182 |
|
183 |
with gr.Accordion("μμ€ν
ν둬ννΈ λ° μ΅μ
μ€μ ", open=False):
|
184 |
system_message = gr.Textbox(label="System Message", value="λλ AI μ‘°μΈμ μν μ΄λ€.")
|
185 |
-
max_tokens = gr.Slider(minimum=1, maximum=8000, value=
|
186 |
temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature")
|
187 |
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")
|
188 |
|
189 |
# μ±λ΄ λ©μμ§ μ²λ¦¬ ν¨μ
|
190 |
def handle_message(message, history, system_message, max_tokens, temperature, top_p):
|
191 |
history = history or []
|
192 |
-
history.append({"role": "user", "content": message})
|
193 |
try:
|
194 |
# μλ΅ μμ±
|
195 |
response_gen = respond(message, history, system_message, max_tokens, temperature, top_p)
|
196 |
response = ""
|
197 |
for partial in response_gen:
|
198 |
response = partial # μ΅μ’
μλ΅
|
|
|
|
|
199 |
history.append({"role": "assistant", "content": response})
|
200 |
except Exception as e:
|
201 |
response = f"μΆλ‘ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
|
|
202 |
history.append({"role": "assistant", "content": response})
|
203 |
return history, ""
|
204 |
|
@@ -255,7 +262,35 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
255 |
gr.Markdown("### κΈ°μ‘΄ Parquet νμΌ")
|
256 |
gr.Markdown(f"**test.parquet νμΌ λ΄μ©:**\n```markdown\n{test_parquet_content}\n```")
|
257 |
|
258 |
-
# μΈ λ²μ§Έ ν:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
with gr.Tab("μ±λ΄ λ°μ΄ν° μ
λ‘λ"):
|
260 |
gr.Markdown("### Parquet νμΌ μ
λ‘λ λ° μ§λ¬ΈνκΈ°")
|
261 |
with gr.Row():
|
@@ -286,16 +321,18 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
286 |
|
287 |
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):
|
288 |
history = history or []
|
289 |
-
history.append({"role": "user", "content": message})
|
290 |
try:
|
291 |
# Parquet λ°μ΄ν°λ₯Ό νμ©ν μ μλ λ‘μ§ μΆκ° κ°λ₯
|
292 |
response_gen = respond(message, history, system_message, max_tokens, temperature, top_p)
|
293 |
response = ""
|
294 |
for partial in response_gen:
|
295 |
response = partial
|
|
|
|
|
296 |
history.append({"role": "assistant", "content": response})
|
297 |
except Exception as e:
|
298 |
response = f"μΆλ‘ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
|
|
299 |
history.append({"role": "assistant", "content": response})
|
300 |
return history, ""
|
301 |
|
@@ -305,34 +342,6 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
305 |
outputs=[chatbot_data_upload, msg_data_upload]
|
306 |
)
|
307 |
|
308 |
-
# λ€ λ²μ§Έ ν: ν
μ€νΈ to csv to parquet λ³ν
|
309 |
-
with gr.Tab("ν
μ€νΈ to csv to parquet λ³ν"):
|
310 |
-
gr.Markdown("### ν
μ€νΈλ₯Ό μ
λ ₯νλ©΄ CSVλ‘ λ³ν ν ParquetμΌλ‘ μλ μ νλ©λλ€.")
|
311 |
-
with gr.Row():
|
312 |
-
with gr.Column():
|
313 |
-
text_input = gr.Textbox(
|
314 |
-
label="ν
μ€νΈ μ
λ ₯ (κ° νμ `id,text,label,metadata` νμμΌλ‘ μ
λ ₯)",
|
315 |
-
lines=10,
|
316 |
-
placeholder="μ: 1,Sample Text,Label1,Metadata1\n2,Another Text,Label2,Metadata2"
|
317 |
-
)
|
318 |
-
convert_button = gr.Button("λ³ν λ° λ€μ΄λ‘λ")
|
319 |
-
convert_status = gr.Textbox(label="λ³ν μν", interactive=False)
|
320 |
-
parquet_preview_convert = gr.Markdown(label="Parquet νμΌ λ―Έλ¦¬λ³΄κΈ°")
|
321 |
-
download_parquet_convert = gr.File(label="Parquet νμΌ λ€μ΄λ‘λ", interactive=False)
|
322 |
-
|
323 |
-
def handle_text_to_parquet(text: str):
|
324 |
-
message, parquet_content, parquet_filename = text_to_parquet(text)
|
325 |
-
if parquet_filename:
|
326 |
-
return message, parquet_content, parquet_filename
|
327 |
-
else:
|
328 |
-
return message, "", None
|
329 |
-
|
330 |
-
convert_button.click(
|
331 |
-
handle_text_to_parquet,
|
332 |
-
inputs=text_input,
|
333 |
-
outputs=[convert_status, parquet_preview_convert, download_parquet_convert]
|
334 |
-
)
|
335 |
-
|
336 |
# μ£Όμ μ¬ν
|
337 |
gr.Markdown("## μ£Όμ μ¬ν")
|
338 |
gr.Markdown("""
|
@@ -341,7 +350,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
341 |
- **LLMκ³Όμ λν**: λ³νλ Parquet νμΌ λ΄μ©μ κΈ°λ°μΌλ‘ LLMμ΄ μλ΅μ μμ±ν©λλ€.
|
342 |
- **Parquet λ€μ΄λ‘λ**: λ³νλ Parquet νμΌμ λ€μ΄λ‘λνλ €λ©΄ λ³νλ νμΌ μμ λ€μ΄λ‘λ λ§ν¬λ₯Ό ν΄λ¦νμΈμ.
|
343 |
- **μ±λ΄ λ°μ΄ν° μ
λ‘λ**: μ±λ΄ λ°μ΄ν° μ
λ‘λ νμμ Parquet νμΌμ μ
λ‘λνλ©΄ ν΄λΉ λ°μ΄ν°λ₯Ό κΈ°λ°μΌλ‘ μ§λ¬Έκ³Ό λ΅λ³μ μ§νν μ μμ΅λλ€.
|
344 |
-
- **ν
μ€νΈ to csv to parquet**:
|
345 |
""")
|
346 |
|
347 |
gr.Markdown("### Gradio μΈν°νμ΄μ€λ₯Ό μ¬μ©νμ¬ LLM λͺ¨λΈκ³Ό μνΈμμ©νμΈμ!")
|
@@ -349,3 +358,5 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
349 |
if __name__ == "__main__":
|
350 |
demo.launch()
|
351 |
|
|
|
|
|
|
167 |
#chatbot-container .message, #chatbot-data-upload .message {
|
168 |
font-size: 14px;
|
169 |
}
|
170 |
+
/* μ
λ ₯μ°½ λ°°κ²½μ λ° κΈμμ λ³κ²½ */
|
171 |
+
textarea, input[type="text"] {
|
172 |
+
background-color: #ffffff; /* ν°μ λ°°κ²½ */
|
173 |
+
color: #000000; /* κ²μ μ κΈμ */
|
174 |
+
}
|
175 |
"""
|
176 |
|
177 |
# Gradio Blocks μΈν°νμ΄μ€ μ€μ
|
178 |
+
with gr.Blocks(css=css) as demo:
|
179 |
gr.Markdown("# LLM μλΉμ€ μΈν°νμ΄μ€")
|
180 |
|
181 |
# 첫 λ²μ§Έ ν: μ±λ΄
|
182 |
with gr.Tab("μ±λ΄"):
|
183 |
gr.Markdown("### LLMκ³Ό λννκΈ°")
|
184 |
chatbot = gr.Chatbot(label="μ±λ΄", type="messages", elem_id="chatbot-container")
|
185 |
+
msg = gr.Textbox(label="λ©μμ§ μ
λ ₯", placeholder="μ¬κΈ°μ λ©μμ§λ₯Ό μ
λ ₯νμΈμ...", elem_id="input-text")
|
186 |
send = gr.Button("μ μ‘")
|
187 |
|
188 |
with gr.Accordion("μμ€ν
ν둬ννΈ λ° μ΅μ
μ€μ ", open=False):
|
189 |
system_message = gr.Textbox(label="System Message", value="λλ AI μ‘°μΈμ μν μ΄λ€.")
|
190 |
+
max_tokens = gr.Slider(minimum=1, maximum=8000, value=1000, label="Max Tokens")
|
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 |
response = ""
|
201 |
for partial in response_gen:
|
202 |
response = partial # μ΅μ’
μλ΅
|
203 |
+
# μ¬μ©μμ λ©μμ§μ μ΄μμ€ν΄νΈμ μλ΅μ νμ€ν 리μ μΆκ°
|
204 |
+
history.append({"role": "user", "content": message})
|
205 |
history.append({"role": "assistant", "content": response})
|
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 |
return history, ""
|
211 |
|
|
|
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 λ³ν"):
|
267 |
+
gr.Markdown("### ν
μ€νΈλ₯Ό μ
λ ₯νλ©΄ CSVλ‘ λ³ν ν ParquetμΌλ‘ μλ μ νλ©λλ€.")
|
268 |
+
with gr.Row():
|
269 |
+
with gr.Column():
|
270 |
+
text_input = gr.Textbox(
|
271 |
+
label="ν
μ€νΈ μ
λ ₯ (κ° νμ `id,text,label,metadata` νμμΌλ‘ μ
λ ₯)",
|
272 |
+
lines=10,
|
273 |
+
placeholder="μ: 1,Sample Text,Label1,Metadata1\n2,Another Text,Label2,Metadata2"
|
274 |
+
)
|
275 |
+
convert_button = gr.Button("λ³ν λ° λ€μ΄λ‘λ")
|
276 |
+
convert_status = gr.Textbox(label="λ³ν μν", interactive=False)
|
277 |
+
parquet_preview_convert = gr.Markdown(label="Parquet νμΌ λ―Έλ¦¬λ³΄κΈ°")
|
278 |
+
download_parquet_convert = gr.File(label="Parquet νμΌ λ€μ΄λ‘λ", interactive=False)
|
279 |
+
|
280 |
+
def handle_text_to_parquet(text: str):
|
281 |
+
message, parquet_content, parquet_filename = text_to_parquet(text)
|
282 |
+
if parquet_filename:
|
283 |
+
return message, parquet_content, parquet_filename
|
284 |
+
else:
|
285 |
+
return message, "", None
|
286 |
+
|
287 |
+
convert_button.click(
|
288 |
+
handle_text_to_parquet,
|
289 |
+
inputs=text_input,
|
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():
|
|
|
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 |
|
|
|
342 |
outputs=[chatbot_data_upload, msg_data_upload]
|
343 |
)
|
344 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
# μ£Όμ μ¬ν
|
346 |
gr.Markdown("## μ£Όμ μ¬ν")
|
347 |
gr.Markdown("""
|
|
|
350 |
- **LLMκ³Όμ λν**: λ³νλ Parquet νμΌ λ΄μ©μ κΈ°λ°μΌλ‘ LLMμ΄ μλ΅μ μμ±ν©λλ€.
|
351 |
- **Parquet λ€μ΄λ‘λ**: λ³νλ Parquet νμΌμ λ€μ΄λ‘λνλ €λ©΄ λ³νλ νμΌ μμ λ€μ΄λ‘λ λ§ν¬λ₯Ό ν΄λ¦νμΈμ.
|
352 |
- **μ±λ΄ λ°μ΄ν° μ
λ‘λ**: μ±λ΄ λ°μ΄ν° μ
λ‘λ νμμ Parquet νμΌμ μ
λ‘λνλ©΄ ν΄λΉ λ°μ΄ν°λ₯Ό κΈ°λ°μΌλ‘ μ§λ¬Έκ³Ό λ΅λ³μ μ§νν μ μμ΅λλ€.
|
353 |
+
- **ν
μ€νΈ to csv to parquet**: μΈ λ²μ§Έ νμμ ν
μ€νΈλ₯Ό μ
λ ₯νλ©΄ μλμΌλ‘ CSVλ‘ λ³νλκ³ , λ€μ Parquet νμΌλ‘ μ νλμ΄ λ€μ΄λ‘λν μ μμ΅λλ€.
|
354 |
""")
|
355 |
|
356 |
gr.Markdown("### Gradio μΈν°νμ΄μ€λ₯Ό μ¬μ©νμ¬ LLM λͺ¨λΈκ³Ό μνΈμμ©νμΈμ!")
|
|
|
358 |
if __name__ == "__main__":
|
359 |
demo.launch()
|
360 |
|
361 |
+
|
362 |
+
|