Update app.py
Browse files
app.py
CHANGED
@@ -42,18 +42,18 @@ def respond(
|
|
42 |
top_p: float = 0.9,
|
43 |
) -> str:
|
44 |
# ์์คํ
ํ๋กฌํํธ ์ค์
|
45 |
-
system_prefix = """๋ฐ๋์ ํ๊ธ๋ก
|
46 |
|
47 |
# ํน์ ๋ช
๋ น์ด ์ฒ๋ฆฌ
|
48 |
if message.lower() == "ํจ์
์ฝ๋ ์คํ":
|
49 |
system_prefix += f"\n\nํจ์
์ฝ๋ ๋ด์ฉ:\n```python\n{fashion_code}\n```"
|
50 |
-
message = "ํจ์
๊ฐ์ํผํ
์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://aiqcamp-fash.hf.space)์ ํตํด
|
51 |
elif message.lower() == "uhd ์ด๋ฏธ์ง ์ฝ๋ ์คํ":
|
52 |
system_prefix += f"\n\nUHD ์ด๋ฏธ์ง ์ฝ๋ ๋ด์ฉ:\n```python\n{uhdimage_code}\n```"
|
53 |
-
message = "UHD ์ด๋ฏธ์ง ์์ฑ์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://openfree-ultpixgen.hf.space)์ ํตํด
|
54 |
elif message.lower() == "mixgen ์ฝ๋ ์คํ":
|
55 |
system_prefix += f"\n\nMixGEN ์ฝ๋ ๋ด์ฉ:\n```python\n{MixGEN_code}\n```"
|
56 |
-
message = "MixGEN3 ์ด๋ฏธ์ง ์์ฑ์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://openfree-mixgen3.hf.space)์ ํตํด
|
57 |
elif message.lower() == "test.parquet ์คํ":
|
58 |
# history์์ parquet_content ์ฐพ๊ธฐ
|
59 |
parquet_content = ""
|
@@ -119,7 +119,7 @@ def upload_csv(file_path: str) -> Tuple[str, str]:
|
|
119 |
# Parquet ํ์ผ ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ
|
120 |
parquet_content = load_parquet(parquet_filename)
|
121 |
|
122 |
-
return f"{parquet_filename} ํ์ผ์ด ์ฑ๊ณต์ ์ผ๋ก ์
๋ก๋๋๊ณ ๋ณํ๋์์ต๋๋ค.",
|
123 |
except Exception as e:
|
124 |
return f"CSV ํ์ผ ์
๋ก๋ ๋ฐ ๋ณํ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", ""
|
125 |
|
@@ -129,13 +129,13 @@ def upload_parquet(file_path: str) -> Tuple[str, str, Dict]:
|
|
129 |
df = pd.read_parquet(file_path, engine='pyarrow')
|
130 |
|
131 |
# Markdown์ผ๋ก ๋ณํํ์ฌ ๋ฏธ๋ฆฌ๋ณด๊ธฐ
|
132 |
-
parquet_content = df.to_markdown(index=False)
|
133 |
|
134 |
return "Parquet ํ์ผ์ด ์ฑ๊ณต์ ์ผ๋ก ์
๋ก๋๋์์ต๋๋ค.", parquet_content, df.to_json()
|
135 |
except Exception as e:
|
136 |
return f"Parquet ํ์ผ ์
๋ก๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", "", {}
|
137 |
|
138 |
-
def text_to_parquet(text: str) -> Tuple[str, str,
|
139 |
try:
|
140 |
# ํ
์คํธ๋ฅผ DataFrame์ผ๋ก ๋ณํ (๊ฐ ํ์ ์ฝค๋ง๋ก ๊ตฌ๋ถ)
|
141 |
data = [line.split(',') for line in text.strip().split('\n')]
|
@@ -151,13 +151,9 @@ def text_to_parquet(text: str) -> Tuple[str, str, bytes]:
|
|
151 |
# Parquet ํ์ผ ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ
|
152 |
parquet_content = load_parquet(parquet_filename)
|
153 |
|
154 |
-
|
155 |
-
with open(parquet_filename, "rb") as f:
|
156 |
-
data = f.read()
|
157 |
-
|
158 |
-
return f"{parquet_filename} ํ์ผ์ด ์ฑ๊ณต์ ์ผ๋ก ๋ณํ๋์์ต๋๋ค.", parquet_content, data
|
159 |
except Exception as e:
|
160 |
-
return f"ํ
์คํธ ๋ณํ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", "",
|
161 |
|
162 |
# CSS ์ค์
|
163 |
css = """
|
@@ -240,16 +236,13 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
240 |
upload_button = gr.Button("์
๋ก๋ ๋ฐ ๋ณํ")
|
241 |
upload_status = gr.Textbox(label="์
๋ก๋ ์ํ", interactive=False)
|
242 |
parquet_preview = gr.Markdown(label="Parquet ํ์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
|
243 |
-
download_button = gr.
|
244 |
|
245 |
-
def handle_csv_upload(file_path: str)
|
246 |
message, parquet_filename = upload_csv(file_path)
|
247 |
if parquet_filename:
|
248 |
-
|
249 |
-
|
250 |
-
data = f.read()
|
251 |
-
filename = os.path.basename(parquet_filename)
|
252 |
-
return message, parquet_filename, (data, filename)
|
253 |
else:
|
254 |
return message, "", None
|
255 |
|
@@ -273,7 +266,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
273 |
parquet_preview_chat = gr.Markdown(label="Parquet ํ์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
|
274 |
parquet_data_state = gr.State()
|
275 |
|
276 |
-
def handle_parquet_upload(file_path: str)
|
277 |
message, parquet_content, parquet_json = upload_parquet(file_path)
|
278 |
if parquet_json:
|
279 |
return message, parquet_content, parquet_json
|
@@ -291,7 +284,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
291 |
msg_data_upload = gr.Textbox(label="๋ฉ์์ง ์
๋ ฅ", placeholder="์ฌ๊ธฐ์ ๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...")
|
292 |
send_data_upload = gr.Button("์ ์ก")
|
293 |
|
294 |
-
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)
|
295 |
history = history or []
|
296 |
history.append({"role": "user", "content": message})
|
297 |
try:
|
@@ -312,8 +305,8 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
312 |
outputs=[chatbot_data_upload, msg_data_upload]
|
313 |
)
|
314 |
|
315 |
-
# ๋ค ๋ฒ์งธ ํญ: ํ
์คํธ to csv to parquet
|
316 |
-
with gr.Tab("ํ
์คํธ to csv to parquet
|
317 |
gr.Markdown("### ํ
์คํธ๋ฅผ ์
๋ ฅํ๋ฉด CSV๋ก ๋ณํ ํ Parquet์ผ๋ก ์๋ ์ ํ๋ฉ๋๋ค.")
|
318 |
with gr.Row():
|
319 |
with gr.Column():
|
@@ -325,13 +318,12 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
325 |
convert_button = gr.Button("๋ณํ ๋ฐ ๋ค์ด๋ก๋")
|
326 |
convert_status = gr.Textbox(label="๋ณํ ์ํ", interactive=False)
|
327 |
parquet_preview_convert = gr.Markdown(label="Parquet ํ์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
|
328 |
-
download_parquet_convert = gr.
|
329 |
|
330 |
-
def handle_text_to_parquet(text: str)
|
331 |
-
message, parquet_content,
|
332 |
-
if
|
333 |
-
|
334 |
-
return message, parquet_content, (file_data, filename)
|
335 |
else:
|
336 |
return message, "", None
|
337 |
|
@@ -355,5 +347,5 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
355 |
gr.Markdown("### Gradio ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ์ฌ LLM ๋ชจ๋ธ๊ณผ ์ํธ์์ฉํ์ธ์!")
|
356 |
|
357 |
if __name__ == "__main__":
|
358 |
-
# share=True๋ Hugging Face Spaces์์ ์ง์๋์ง ์์ผ๋ฏ๋ก ์ ๊ฑฐ
|
359 |
demo.launch()
|
|
|
|
42 |
top_p: float = 0.9,
|
43 |
) -> str:
|
44 |
# ์์คํ
ํ๋กฌํํธ ์ค์
|
45 |
+
system_prefix = """๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ ๊ฒ. ๋๋ ์ฃผ์ด์ง ์์ค์ฝ๋๋ฅผ ๊ธฐ๋ฐ์ผ๋ก "์๋น์ค ์ฌ์ฉ ์ค๋ช
๋ฐ ์๋ด, Q&A๋ฅผ ํ๋ ์ญํ ์ด๋ค". ์์ฃผ ์น์ ํ๊ณ ์์ธํ๊ฒ 4000ํ ํฐ ์ด์ Markdown ํ์์ผ๋ก ์์ฑํ๋ผ. ๋๋ ์ฝ๋๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ฌ์ฉ ์ค๋ช
๋ฐ ์ง์ ์๋ต์ ์งํํ๋ฉฐ, ์ด์ฉ์์๊ฒ ๋์์ ์ฃผ์ด์ผ ํ๋ค. ์ด์ฉ์๊ฐ ๊ถ๊ธํดํ ๋งํ ๋ด์ฉ์ ์น์ ํ๊ฒ ์๋ ค์ฃผ๋๋ก ํ๋ผ. ์ฝ๋ ์ ์ฒด ๋ด์ฉ์ ๋ํด์๋ ๋ณด์์ ์ ์งํ๊ณ , ํค ๊ฐ ๋ฐ ์๋ํฌ์ธํธ์ ๊ตฌ์ฒด์ ์ธ ๋ชจ๋ธ์ ๊ณต๊ฐํ์ง ๋ง๋ผ."""
|
46 |
|
47 |
# ํน์ ๋ช
๋ น์ด ์ฒ๋ฆฌ
|
48 |
if message.lower() == "ํจ์
์ฝ๋ ์คํ":
|
49 |
system_prefix += f"\n\nํจ์
์ฝ๋ ๋ด์ฉ:\n```python\n{fashion_code}\n```"
|
50 |
+
message = "ํจ์
๊ฐ์ํผํ
์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://aiqcamp-fash.hf.space)์ ํตํด ํ
์คํธํด๋ณด๋ผ๊ณ ์ถ๋ ฅํ๋ผ."
|
51 |
elif message.lower() == "uhd ์ด๋ฏธ์ง ์ฝ๋ ์คํ":
|
52 |
system_prefix += f"\n\nUHD ์ด๋ฏธ์ง ์ฝ๋ ๋ด์ฉ:\n```python\n{uhdimage_code}\n```"
|
53 |
+
message = "UHD ์ด๋ฏธ์ง ์์ฑ์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://openfree-ultpixgen.hf.space)์ ํตํด ํ
์คํธํด๋ณด๋ผ๊ณ ์ถ๋ ฅํ๋ผ."
|
54 |
elif message.lower() == "mixgen ์ฝ๋ ์คํ":
|
55 |
system_prefix += f"\n\nMixGEN ์ฝ๋ ๋ด์ฉ:\n```python\n{MixGEN_code}\n```"
|
56 |
+
message = "MixGEN3 ์ด๋ฏธ์ง ์์ฑ์ ๋ํ ๋ด์ฉ์ ํ์ตํ์๊ณ , ์ค๋ช
ํ ์ค๋น๊ฐ ๋์ด์๋ค๊ณ ์๋ฆฌ๊ณ ์๋น์ค URL(https://openfree-mixgen3.hf.space)์ ํตํด ํ
์คํธํด๋ณด๋ผ๊ณ ์ถ๋ ฅํ๋ผ."
|
57 |
elif message.lower() == "test.parquet ์คํ":
|
58 |
# history์์ parquet_content ์ฐพ๊ธฐ
|
59 |
parquet_content = ""
|
|
|
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 |
|
|
|
129 |
df = pd.read_parquet(file_path, engine='pyarrow')
|
130 |
|
131 |
# Markdown์ผ๋ก ๋ณํํ์ฌ ๋ฏธ๋ฆฌ๋ณด๊ธฐ
|
132 |
+
parquet_content = df.head(10).to_markdown(index=False)
|
133 |
|
134 |
return "Parquet ํ์ผ์ด ์ฑ๊ณต์ ์ผ๋ก ์
๋ก๋๋์์ต๋๋ค.", parquet_content, df.to_json()
|
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:
|
140 |
# ํ
์คํธ๋ฅผ DataFrame์ผ๋ก ๋ณํ (๊ฐ ํ์ ์ฝค๋ง๋ก ๊ตฌ๋ถ)
|
141 |
data = [line.split(',') for line in text.strip().split('\n')]
|
|
|
151 |
# Parquet ํ์ผ ๋ด์ฉ ๋ฏธ๋ฆฌ๋ณด๊ธฐ
|
152 |
parquet_content = load_parquet(parquet_filename)
|
153 |
|
154 |
+
return f"{parquet_filename} ํ์ผ์ด ์ฑ๊ณต์ ์ผ๋ก ๋ณํ๋์์ต๋๋ค.", parquet_content, parquet_filename
|
|
|
|
|
|
|
|
|
155 |
except Exception as e:
|
156 |
+
return f"ํ
์คํธ ๋ณํ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}", "", ""
|
157 |
|
158 |
# CSS ์ค์
|
159 |
css = """
|
|
|
236 |
upload_button = gr.Button("์
๋ก๋ ๋ฐ ๋ณํ")
|
237 |
upload_status = gr.Textbox(label="์
๋ก๋ ์ํ", interactive=False)
|
238 |
parquet_preview = gr.Markdown(label="Parquet ํ์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
|
239 |
+
download_button = gr.File(label="Parquet ํ์ผ ๋ค์ด๋ก๋", interactive=False)
|
240 |
|
241 |
+
def handle_csv_upload(file_path: str):
|
242 |
message, parquet_filename = upload_csv(file_path)
|
243 |
if parquet_filename:
|
244 |
+
parquet_content = load_parquet(parquet_filename)
|
245 |
+
return message, parquet_content, parquet_filename
|
|
|
|
|
|
|
246 |
else:
|
247 |
return message, "", None
|
248 |
|
|
|
266 |
parquet_preview_chat = gr.Markdown(label="Parquet ํ์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
|
267 |
parquet_data_state = gr.State()
|
268 |
|
269 |
+
def handle_parquet_upload(file_path: str):
|
270 |
message, parquet_content, parquet_json = upload_parquet(file_path)
|
271 |
if parquet_json:
|
272 |
return message, parquet_content, parquet_json
|
|
|
284 |
msg_data_upload = gr.Textbox(label="๋ฉ์์ง ์
๋ ฅ", placeholder="์ฌ๊ธฐ์ ๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...")
|
285 |
send_data_upload = gr.Button("์ ์ก")
|
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:
|
|
|
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():
|
|
|
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 |
|
|
|
347 |
gr.Markdown("### Gradio ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ์ฌ LLM ๋ชจ๋ธ๊ณผ ์ํธ์์ฉํ์ธ์!")
|
348 |
|
349 |
if __name__ == "__main__":
|
|
|
350 |
demo.launch()
|
351 |
+
|