ginipick commited on
Commit
0fbbd89
โ€ข
1 Parent(s): 8f71308

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -70
app.py CHANGED
@@ -2,13 +2,12 @@ import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import os
4
  import pandas as pd
5
- from typing import List, Dict
6
 
7
  # ์ถ”๋ก  API ํด๋ผ์ด์–ธํŠธ ์„ค์ •
8
  hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=os.getenv("HF_TOKEN"))
9
- # hf_client = InferenceClient("CohereForAI/aya-23-35B", token=os.getenv("HF_TOKEN"))
10
 
11
- def load_code(filename):
12
  try:
13
  with open(filename, 'r', encoding='utf-8') as file:
14
  return file.read()
@@ -17,10 +16,9 @@ def load_code(filename):
17
  except Exception as e:
18
  return f"ํŒŒ์ผ์„ ์ฝ๋Š” ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
19
 
20
- def load_parquet(filename):
21
  try:
22
  df = pd.read_parquet(filename, engine='pyarrow')
23
- # ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„์˜ ์ฒซ ๋ช‡ ํ–‰์„ ๋ฌธ์ž์—ด๋กœ ๋ณ€ํ™˜ (Markdown ํ‘œ ํ˜•์‹)
24
  return df.head(10).to_markdown(index=False)
25
  except FileNotFoundError:
26
  return f"{filename} ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
@@ -36,28 +34,28 @@ MixGEN_code = load_code('mgen.cod')
36
  test_parquet_content = load_parquet('test.parquet')
37
 
38
  def respond(
39
- message,
40
  history: List[Dict[str, str]],
41
- system_message="", # ๊ธฐ๋ณธ๊ฐ’ ์ถ”๊ฐ€
42
- max_tokens=4000, # ๊ธฐ๋ณธ๊ฐ’ ๋ณ€๊ฒฝ
43
- temperature=0.7, # ๊ธฐ๋ณธ๊ฐ’ ์œ ์ง€
44
- top_p=0.9, # ๊ธฐ๋ณธ๊ฐ’ ์œ ์ง€
45
- ):
46
  # ์‹œ์Šคํ…œ ํ”„๋กฌํ”„ํŠธ ์„ค์ •
47
  system_prefix = """๋ฐ˜๋“œ์‹œ ํ•œ๊ธ€๋กœ ๋‹ต๋ณ€ํ• ๊ฒƒ. ๋„ˆ๋Š” ์ฃผ์–ด์ง„ ์†Œ์Šค์ฝ”๋“œ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ "์„œ๋น„์Šค ์‚ฌ์šฉ ์„ค๋ช… ๋ฐ ์•ˆ๋‚ด, Q&A๋ฅผ ํ•˜๋Š” ์—ญํ• ์ด๋‹ค". ์•„์ฃผ ์นœ์ ˆํ•˜๊ณ  ์ž์„ธํ•˜๊ฒŒ 4000ํ† ํฐ ์ด์ƒ Markdown ํ˜•์‹์œผ๋กœ ์ž‘์„ฑํ•˜๋ผ. ๋„ˆ๋Š” ์ฝ”๋“œ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์‚ฌ์šฉ ์„ค๋ช… ๋ฐ ์งˆ์˜ ์‘๋‹ต์„ ์ง„ํ–‰ํ•˜๋ฉฐ, ์ด์šฉ์ž์—๊ฒŒ ๋„์›€์„ ์ฃผ์–ด์•ผ ํ•œ๋‹ค. ์ด์šฉ์ž๊ฐ€ ๊ถ๊ธˆํ•ด ํ•  ๋งŒํ•œ ๋‚ด์šฉ์— ์นœ์ ˆํ•˜๊ฒŒ ์•Œ๋ ค์ฃผ๋„๋ก ํ•˜๋ผ. ์ฝ”๋“œ ์ „์ฒด ๋‚ด์šฉ์— ๋Œ€ํ•ด์„œ๋Š” ๋ณด์•ˆ์„ ์œ ์ง€ํ•˜๊ณ , ํ‚ค ๊ฐ’ ๋ฐ ์—”๋“œํฌ์ธํŠธ์™€ ๊ตฌ์ฒด์ ์ธ ๋ชจ๋ธ์€ ๊ณต๊ฐœํ•˜์ง€ ๋งˆ๋ผ."""
48
-
49
- # ๋ช…๋ น์–ด ์ฒ˜๋ฆฌ
50
  if message.lower() == "ํŒจ์…˜ ์ฝ”๋“œ ์‹คํ–‰":
51
- system_message += f"\n\nํŒจ์…˜ ์ฝ”๋“œ ๋‚ด์šฉ:\n```python\n{fashion_code}\n```"
52
  message = "ํŒจ์…˜ ๊ฐ€์ƒํ”ผํŒ…์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ํ•™์Šตํ•˜์˜€๊ณ , ์„ค๋ช…ํ•  ์ค€๋น„๊ฐ€ ๋˜์–ด์žˆ๋‹ค๊ณ  ์•Œ๋ฆฌ๊ณ  ์„œ๋น„์Šค URL(https://aiqcamp-fash.hf.space)์„ ํ†ตํ•ด ํ…Œ์ŠคํŠธ ํ•ด๋ณด๋ผ๊ณ  ์ถœ๋ ฅํ•˜๋ผ."
53
  elif message.lower() == "uhd ์ด๋ฏธ์ง€ ์ฝ”๋“œ ์‹คํ–‰":
54
- system_message += f"\n\nUHD ์ด๋ฏธ์ง€ ์ฝ”๋“œ ๋‚ด์šฉ:\n```python\n{uhdimage_code}\n```"
55
  message = "UHD ์ด๋ฏธ์ง€ ์ƒ์„ฑ์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ํ•™์Šตํ•˜์˜€๊ณ , ์„ค๋ช…ํ•  ์ค€๋น„๊ฐ€ ๋˜์–ด์žˆ๋‹ค๊ณ  ์•Œ๋ฆฌ๊ณ  ์„œ๋น„์Šค URL(https://openfree-ultpixgen.hf.space)์„ ํ†ตํ•ด ํ…Œ์ŠคํŠธ ํ•ด๋ณด๋ผ๊ณ  ์ถœ๋ ฅํ•˜๋ผ."
56
  elif message.lower() == "mixgen ์ฝ”๋“œ ์‹คํ–‰":
57
- system_message += f"\n\nMixGEN ์ฝ”๋“œ ๋‚ด์šฉ:\n```python\n{MixGEN_code}\n```"
58
  message = "MixGEN3 ์ด๋ฏธ์ง€ ์ƒ์„ฑ์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ํ•™์Šตํ•˜์˜€๊ณ , ์„ค๋ช…ํ•  ์ค€๋น„๊ฐ€ ๋˜์–ด์žˆ๋‹ค๊ณ  ์•Œ๋ฆฌ๊ณ  ์„œ๋น„์Šค URL(https://openfree-mixgen3.hf.space)์„ ํ†ตํ•ด ํ…Œ์ŠคํŠธ ํ•ด๋ณด๋ผ๊ณ  ์ถœ๋ ฅํ•˜๋ผ."
59
  elif message.lower() == "test.parquet ์‹คํ–‰":
60
- # Parquet ๋‚ด์šฉ ์ฐธ์กฐ
61
  parquet_content = ""
62
  for item in history:
63
  if item['role'] == 'assistant' and 'test.parquet ํŒŒ์ผ ๋‚ด์šฉ' in item['content']:
@@ -66,19 +64,20 @@ def respond(
66
  except IndexError:
67
  parquet_content = ""
68
  break
69
- system_message += f"\n\ntest.parquet ํŒŒ์ผ ๋‚ด์šฉ:\n```markdown\n{parquet_content}\n```"
70
  message = "test.parquet ํŒŒ์ผ์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ํ•™์Šตํ•˜์˜€๊ณ , ๊ด€๋ จ ์„ค๋ช… ๋ฐ Q&A๋ฅผ ์ง„ํ–‰ํ•  ์ค€๋น„๊ฐ€ ๋˜์–ด์žˆ๋‹ค. ๊ถ๊ธˆํ•œ ์ ์ด ์žˆ์œผ๋ฉด ๋ฌผ์–ด๋ณด๋ผ."
71
  elif message.lower() == "csv ์—…๋กœ๋“œ":
72
  message = "CSV ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜๋ ค๋ฉด ๋‘ ๋ฒˆ์งธ ํƒญ์„ ์‚ฌ์šฉํ•˜์„ธ์š”."
73
 
74
- # ์‹œ์Šคํ…œ ๋ฉ”์‹œ์ง€์™€ ์‚ฌ์šฉ์ž ๋ฉ”์‹œ์ง€ ๊ฒฐํ•ฉ
75
- messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
76
  for chat in history:
77
  messages.append({"role": chat['role'], "content": chat['content']})
78
  messages.append({"role": "user", "content": message})
79
 
80
  response = ""
81
  try:
 
82
  for msg in hf_client.chat_completion(
83
  messages,
84
  max_tokens=max_tokens,
@@ -93,18 +92,18 @@ def respond(
93
  except Exception as e:
94
  yield f"์ถ”๋ก  ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
95
 
96
- def upload_csv(file_path):
97
  try:
98
- # CSV ํŒŒ์ผ ์ฝ๊ธฐ (๊ตฌ๋ถ„์ž ์ฝค๋งˆ)
99
  df = pd.read_csv(file_path, sep=',')
100
 
101
- # CSV ํŒŒ์ผ์˜ ์ปฌ๋Ÿผ ํ™•์ธ
102
  required_columns = {'id', 'text', 'label', 'metadata'}
103
  available_columns = set(df.columns)
104
  missing_columns = required_columns - available_columns
105
 
106
  if missing_columns:
107
- return f"CSV ํŒŒ์ผ์— ๋‹ค์Œ ํ•„์ˆ˜ ์ปฌ๋Ÿผ์ด ๋ˆ„๋ฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค: {', '.join(missing_columns)}", None
108
 
109
  # ๋ฐ์ดํ„ฐ ํด๋ Œ์ง•
110
  df.drop_duplicates(inplace=True)
@@ -117,28 +116,28 @@ def upload_csv(file_path):
117
  parquet_filename = os.path.splitext(os.path.basename(file_path))[0] + '.parquet'
118
  df.to_parquet(parquet_filename, engine='pyarrow', compression='snappy')
119
 
120
- # Parquet ํŒŒ์ผ ๋กœ๋“œ
121
  parquet_content = load_parquet(parquet_filename)
122
 
123
- return f"{parquet_filename} ํŒŒ์ผ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์—…๋กœ๋“œ๋˜๊ณ  ๋ณ€ํ™˜๋˜์—ˆ์Šต๋‹ˆ๋‹ค.", parquet_filename
124
  except Exception as e:
125
- return f"CSV ํŒŒ์ผ ์—…๋กœ๋“œ ๋ฐ ๋ณ€ํ™˜ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}", None
126
 
127
- def upload_parquet(file_path):
128
  try:
129
  # Parquet ํŒŒ์ผ ์ฝ๊ธฐ
130
  df = pd.read_parquet(file_path, engine='pyarrow')
131
 
132
- # ๋ฐ์ดํ„ฐํ”„๋ ˆ์ž„์„ Markdown์œผ๋กœ ๋ณ€ํ™˜
133
  parquet_content = df.to_markdown(index=False)
134
 
135
- return "Parquet ํŒŒ์ผ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์—…๋กœ๋“œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.", parquet_content, df.to_json() # JSON์œผ๋กœ ๋ฐ์ดํ„ฐ ์ €์žฅ
136
  except Exception as e:
137
- return f"Parquet ํŒŒ์ผ ์—…๋กœ๋“œ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}", None, None
138
 
139
- def text_to_parquet(text):
140
  try:
141
- # ํ…์ŠคํŠธ๋ฅผ DataFrame์œผ๋กœ ๋ณ€ํ™˜ (์˜ˆ์‹œ: ๊ฐ ์ค„์„ ์ƒˆ๋กœ์šด ํ–‰์œผ๋กœ, ์ฝค๋งˆ๋กœ ๊ตฌ๋ถ„)
142
  data = [line.split(',') for line in text.strip().split('\n')]
143
  df = pd.DataFrame(data, columns=['id', 'text', 'label', 'metadata'])
144
 
@@ -149,17 +148,18 @@ def text_to_parquet(text):
149
  parquet_filename = 'text_to_parquet.parquet'
150
  df.to_parquet(parquet_filename, engine='pyarrow', compression='snappy')
151
 
152
- # Parquet ํŒŒ์ผ ๋กœ๋“œ
153
  parquet_content = load_parquet(parquet_filename)
154
 
155
- # ํŒŒ์ผ ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์–ด ๋ฐ”์ด๋„ˆ๋ฆฌ๋กœ ๋ฐ˜ํ™˜
156
  with open(parquet_filename, "rb") as f:
157
  data = f.read()
158
 
159
- return f"{parquet_filename} ํŒŒ์ผ์ด ์„ฑ๊ณต์ ์œผ๋กœ ๋ณ€ํ™˜๋˜์—ˆ์Šต๋‹ˆ๋‹ค.", parquet_content, (parquet_filename, data)
160
  except Exception as e:
161
- return f"ํ…์ŠคํŠธ ๋ณ€ํ™˜ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}", "", None
162
 
 
163
  css = """
164
  footer {
165
  visibility: hidden;
@@ -177,6 +177,7 @@ footer {
177
  with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
178
  gr.Markdown("# LLM ์„œ๋น„์Šค ์ธํ„ฐํŽ˜์ด์Šค")
179
 
 
180
  with gr.Tab("์ฑ—๋ด‡"):
181
  gr.Markdown("### LLM๊ณผ ๋Œ€ํ™”ํ•˜๊ธฐ")
182
  chatbot = gr.Chatbot(label="์ฑ—๋ด‡", type="messages", elem_id="chatbot-container")
@@ -191,18 +192,18 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
191
 
192
  # ์ฑ—๋ด‡ ๋ฉ”์‹œ์ง€ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜
193
  def handle_message(message, history, system_message, max_tokens, temperature, top_p):
194
- # Update history with user message
195
  history = history or []
196
  history.append({"role": "user", "content": message})
197
- # Generate response
198
- response = ""
199
  try:
200
- for token in respond(message, history, system_message, max_tokens, temperature, top_p):
201
- response = token
202
- # Update history with assistant response
 
 
203
  history.append({"role": "assistant", "content": response})
204
  except Exception as e:
205
- history.append({"role": "assistant", "content": f"์ถ”๋ก  ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"})
 
206
  return history, ""
207
 
208
  send.click(
@@ -211,9 +212,9 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
211
  outputs=[chatbot, msg]
212
  )
213
 
214
- # ์˜ˆ์ œ ๋ฒ„ํŠผ (๋ณต์›๋œ examples)
215
  with gr.Accordion("์˜ˆ์ œ", open=False):
216
- example_buttons = gr.Examples(
217
  examples=[
218
  ["ํŒจ์…˜ ์ฝ”๋“œ ์‹คํ–‰"],
219
  ["UHD ์ด๋ฏธ์ง€ ์ฝ”๋“œ ์‹คํ–‰"],
@@ -230,6 +231,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
230
  label="์˜ˆ์ œ ์„ ํƒ",
231
  )
232
 
 
233
  with gr.Tab("๋ฐ์ดํ„ฐ ๋ณ€ํ™˜"):
234
  gr.Markdown("### CSV ํŒŒ์ผ ์—…๋กœ๋“œ ๋ฐ Parquet ๋ณ€ํ™˜")
235
  with gr.Row():
@@ -238,16 +240,16 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
238
  upload_button = gr.Button("์—…๋กœ๋“œ ๋ฐ ๋ณ€ํ™˜")
239
  upload_status = gr.Textbox(label="์—…๋กœ๋“œ ์ƒํƒœ", interactive=False)
240
  parquet_preview = gr.Markdown(label="Parquet ํŒŒ์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
241
- download_button = gr.File(label="Parquet ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ", type="binary", interactive=False)
242
 
243
- # ์—…๋กœ๋“œ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ์‹คํ–‰ํ•  ํ•จ์ˆ˜
244
- def handle_csv_upload(file_path):
245
  message, parquet_filename = upload_csv(file_path)
246
  if parquet_filename:
247
- # ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ฐ”์ด๋„ˆ๋ฆฌ ๋ฐ์ดํ„ฐ๋กœ ์ฝ๊ธฐ
248
  with open(parquet_filename, "rb") as f:
249
  data = f.read()
250
- return message, load_parquet(parquet_filename), (parquet_filename, data)
 
251
  else:
252
  return message, "", None
253
 
@@ -260,6 +262,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
260
  gr.Markdown("### ๊ธฐ์กด Parquet ํŒŒ์ผ")
261
  gr.Markdown(f"**test.parquet ํŒŒ์ผ ๋‚ด์šฉ:**\n```markdown\n{test_parquet_content}\n```")
262
 
 
263
  with gr.Tab("์ฑ—๋ด‡ ๋ฐ์ดํ„ฐ ์—…๋กœ๋“œ"):
264
  gr.Markdown("### Parquet ํŒŒ์ผ ์—…๋กœ๋“œ ๋ฐ ์งˆ๋ฌธํ•˜๊ธฐ")
265
  with gr.Row():
@@ -268,15 +271,14 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
268
  parquet_upload_button = gr.Button("์—…๋กœ๋“œ")
269
  parquet_upload_status = gr.Textbox(label="์—…๋กœ๋“œ ์ƒํƒœ", interactive=False)
270
  parquet_preview_chat = gr.Markdown(label="Parquet ํŒŒ์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
271
- # ์ƒํƒœ๋ฅผ ์ €์žฅํ•  Hidden State
272
  parquet_data_state = gr.State()
273
 
274
- def handle_parquet_upload(file_path):
275
  message, parquet_content, parquet_json = upload_parquet(file_path)
276
  if parquet_json:
277
  return message, parquet_content, parquet_json
278
  else:
279
- return message, "", None
280
 
281
  parquet_upload_button.click(
282
  handle_parquet_upload,
@@ -289,21 +291,19 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
289
  msg_data_upload = gr.Textbox(label="๋ฉ”์‹œ์ง€ ์ž…๋ ฅ", placeholder="์—ฌ๊ธฐ์— ๋ฉ”์‹œ์ง€๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”...")
290
  send_data_upload = gr.Button("์ „์†ก")
291
 
292
- # ์ฑ—๋ด‡ ๋ฉ”์‹œ์ง€ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜ (๋ฐ์ดํ„ฐ ์—…๋กœ๋“œ ๋ฒ„์ „)
293
- def handle_message_data_upload(message, history, system_message, max_tokens, temperature, top_p, parquet_data):
294
- # Parquet ๋ฐ์ดํ„ฐ๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋กœ์ง์„ ์ถ”๊ฐ€ (์˜ˆ: ๋ฐ์ดํ„ฐ ๋ถ„์„, ์งˆ์˜์‘๋‹ต)
295
- # ํ˜„์žฌ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ฉ”์‹œ์ง€๋ฅผ ์ฒ˜๋ฆฌ
296
  history = history or []
297
  history.append({"role": "user", "content": message})
298
- # Generate response
299
- response = ""
300
  try:
301
- for token in respond(message, history, system_message, max_tokens, temperature, top_p):
302
- response = token
303
- # Update history with assistant response
 
 
304
  history.append({"role": "assistant", "content": response})
305
  except Exception as e:
306
- history.append({"role": "assistant", "content": f"์ถ”๋ก  ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"})
 
307
  return history, ""
308
 
309
  send_data_upload.click(
@@ -312,21 +312,26 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
312
  outputs=[chatbot_data_upload, msg_data_upload]
313
  )
314
 
 
315
  with gr.Tab("ํ…์ŠคํŠธ to csv to parquet ๋ณ€ํ™”"):
316
  gr.Markdown("### ํ…์ŠคํŠธ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด CSV๋กœ ๋ณ€ํ™˜ ํ›„ Parquet์œผ๋กœ ์ž๋™ ์ „ํ™˜๋ฉ๋‹ˆ๋‹ค.")
317
  with gr.Row():
318
  with gr.Column():
319
- text_input = gr.Textbox(label="ํ…์ŠคํŠธ ์ž…๋ ฅ (๊ฐ ํ–‰์€ `id,text,label,metadata` ํ˜•์‹์œผ๋กœ ์ž…๋ ฅ)", lines=10, placeholder="์˜ˆ: 1,Sample Text,Label1,Metadata1\n2,Another Text,Label2,Metadata2")
 
 
 
 
320
  convert_button = gr.Button("๋ณ€ํ™˜ ๋ฐ ๋‹ค์šด๋กœ๋“œ")
321
  convert_status = gr.Textbox(label="๋ณ€ํ™˜ ์ƒํƒœ", interactive=False)
322
  parquet_preview_convert = gr.Markdown(label="Parquet ํŒŒ์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
323
- download_parquet_convert = gr.File(label="Parquet ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ", type="binary", interactive=False)
324
 
325
- # ๋ณ€ํ™˜ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ์‹คํ–‰ํ•  ํ•จ์ˆ˜
326
- def handle_text_to_parquet(text):
327
  message, parquet_content, file_data = text_to_parquet(text)
328
  if file_data:
329
- return message, parquet_content, file_data
 
330
  else:
331
  return message, "", None
332
 
@@ -336,6 +341,7 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
336
  outputs=[convert_status, parquet_preview_convert, download_parquet_convert]
337
  )
338
 
 
339
  gr.Markdown("## ์ฃผ์˜ ์‚ฌํ•ญ")
340
  gr.Markdown("""
341
  - **CSV ์—…๋กœ๋“œ**: CSV ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜๋ฉด ์ž๋™์œผ๋กœ Parquet ํŒŒ์ผ๋กœ ๋ณ€ํ™˜๋ฉ๋‹ˆ๋‹ค. CSV ํŒŒ์ผ์€ ๋ฐ˜๋“œ์‹œ **์ฝค๋งˆ(`,`)**๋กœ ๊ตฌ๋ถ„๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
@@ -349,4 +355,5 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
349
  gr.Markdown("### Gradio ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ LLM ๋ชจ๋ธ๊ณผ ์ƒํ˜ธ์ž‘์šฉํ•˜์„ธ์š”!")
350
 
351
  if __name__ == "__main__":
352
- demo.launch(share=True)
 
 
2
  from huggingface_hub import InferenceClient
3
  import os
4
  import pandas as pd
5
+ from typing import List, Dict, Tuple
6
 
7
  # ์ถ”๋ก  API ํด๋ผ์ด์–ธํŠธ ์„ค์ •
8
  hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=os.getenv("HF_TOKEN"))
 
9
 
10
+ def load_code(filename: str) -> str:
11
  try:
12
  with open(filename, 'r', encoding='utf-8') as file:
13
  return file.read()
 
16
  except Exception as e:
17
  return f"ํŒŒ์ผ์„ ์ฝ๋Š” ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
18
 
19
+ def load_parquet(filename: str) -> str:
20
  try:
21
  df = pd.read_parquet(filename, engine='pyarrow')
 
22
  return df.head(10).to_markdown(index=False)
23
  except FileNotFoundError:
24
  return f"{filename} ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
 
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 = 4000,
41
+ temperature: float = 0.7,
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 = ""
60
  for item in history:
61
  if item['role'] == 'assistant' and 'test.parquet ํŒŒ์ผ ๋‚ด์šฉ' in item['content']:
 
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,
 
92
  except Exception as e:
93
  yield f"์ถ”๋ก  ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
94
 
95
+ def upload_csv(file_path: str) -> Tuple[str, str]:
96
  try:
97
+ # CSV ํŒŒ์ผ ์ฝ๊ธฐ
98
  df = pd.read_csv(file_path, sep=',')
99
 
100
+ # ํ•„์ˆ˜ ์ปฌ๋Ÿผ ํ™•์ธ
101
  required_columns = {'id', 'text', 'label', 'metadata'}
102
  available_columns = set(df.columns)
103
  missing_columns = required_columns - available_columns
104
 
105
  if missing_columns:
106
+ return f"CSV ํŒŒ์ผ์— ๋‹ค์Œ ํ•„์ˆ˜ ์ปฌ๋Ÿผ์ด ๋ˆ„๋ฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค: {', '.join(missing_columns)}", ""
107
 
108
  # ๋ฐ์ดํ„ฐ ํด๋ Œ์ง•
109
  df.drop_duplicates(inplace=True)
 
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_content
123
  except Exception as e:
124
+ return f"CSV ํŒŒ์ผ ์—…๋กœ๋“œ ๋ฐ ๋ณ€ํ™˜ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}", ""
125
 
126
+ def upload_parquet(file_path: str) -> Tuple[str, str, Dict]:
127
  try:
128
  # Parquet ํŒŒ์ผ ์ฝ๊ธฐ
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, bytes]:
139
  try:
140
+ # ํ…์ŠคํŠธ๋ฅผ DataFrame์œผ๋กœ ๋ณ€ํ™˜ (๊ฐ ํ–‰์€ ์ฝค๋งˆ๋กœ ๊ตฌ๋ถ„)
141
  data = [line.split(',') for line in text.strip().split('\n')]
142
  df = pd.DataFrame(data, columns=['id', 'text', 'label', 'metadata'])
143
 
 
148
  parquet_filename = 'text_to_parquet.parquet'
149
  df.to_parquet(parquet_filename, engine='pyarrow', compression='snappy')
150
 
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)}", "", b""
161
 
162
+ # CSS ์„ค์ •
163
  css = """
164
  footer {
165
  visibility: hidden;
 
177
  with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
178
  gr.Markdown("# LLM ์„œ๋น„์Šค ์ธํ„ฐํŽ˜์ด์Šค")
179
 
180
+ # ์ฒซ ๋ฒˆ์งธ ํƒญ: ์ฑ—๋ด‡
181
  with gr.Tab("์ฑ—๋ด‡"):
182
  gr.Markdown("### LLM๊ณผ ๋Œ€ํ™”ํ•˜๊ธฐ")
183
  chatbot = gr.Chatbot(label="์ฑ—๋ด‡", type="messages", elem_id="chatbot-container")
 
192
 
193
  # ์ฑ—๋ด‡ ๋ฉ”์‹œ์ง€ ์ฒ˜๋ฆฌ ํ•จ์ˆ˜
194
  def handle_message(message, history, system_message, max_tokens, temperature, top_p):
 
195
  history = history or []
196
  history.append({"role": "user", "content": message})
 
 
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
  history.append({"role": "assistant", "content": response})
204
  except Exception as e:
205
+ response = f"์ถ”๋ก  ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
206
+ history.append({"role": "assistant", "content": response})
207
  return history, ""
208
 
209
  send.click(
 
212
  outputs=[chatbot, msg]
213
  )
214
 
215
+ # ์˜ˆ์ œ ๋ณต์›
216
  with gr.Accordion("์˜ˆ์ œ", open=False):
217
+ gr.Examples(
218
  examples=[
219
  ["ํŒจ์…˜ ์ฝ”๋“œ ์‹คํ–‰"],
220
  ["UHD ์ด๋ฏธ์ง€ ์ฝ”๋“œ ์‹คํ–‰"],
 
231
  label="์˜ˆ์ œ ์„ ํƒ",
232
  )
233
 
234
+ # ๋‘ ๋ฒˆ์งธ ํƒญ: ๋ฐ์ดํ„ฐ ๋ณ€ํ™˜
235
  with gr.Tab("๋ฐ์ดํ„ฐ ๋ณ€ํ™˜"):
236
  gr.Markdown("### CSV ํŒŒ์ผ ์—…๋กœ๋“œ ๋ฐ Parquet ๋ณ€ํ™˜")
237
  with gr.Row():
 
240
  upload_button = gr.Button("์—…๋กœ๋“œ ๋ฐ ๋ณ€ํ™˜")
241
  upload_status = gr.Textbox(label="์—…๋กœ๋“œ ์ƒํƒœ", interactive=False)
242
  parquet_preview = gr.Markdown(label="Parquet ํŒŒ์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
243
+ download_button = gr.Download(label="Parquet ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ")
244
 
245
+ def handle_csv_upload(file_path: str) -> Tuple[str, str, Tuple[bytes, str]]:
 
246
  message, parquet_filename = upload_csv(file_path)
247
  if parquet_filename:
248
+ # Parquet ํŒŒ์ผ ์ฝ๊ธฐ
249
  with open(parquet_filename, "rb") as f:
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
 
 
262
  gr.Markdown("### ๊ธฐ์กด Parquet ํŒŒ์ผ")
263
  gr.Markdown(f"**test.parquet ํŒŒ์ผ ๋‚ด์šฉ:**\n```markdown\n{test_parquet_content}\n```")
264
 
265
+ # ์„ธ ๋ฒˆ์งธ ํƒญ: ์ฑ—๋ด‡ ๋ฐ์ดํ„ฐ ์—…๋กœ๋“œ
266
  with gr.Tab("์ฑ—๋ด‡ ๋ฐ์ดํ„ฐ ์—…๋กœ๋“œ"):
267
  gr.Markdown("### Parquet ํŒŒ์ผ ์—…๋กœ๋“œ ๋ฐ ์งˆ๋ฌธํ•˜๊ธฐ")
268
  with gr.Row():
 
271
  parquet_upload_button = gr.Button("์—…๋กœ๋“œ")
272
  parquet_upload_status = gr.Textbox(label="์—…๋กœ๋“œ ์ƒํƒœ", interactive=False)
273
  parquet_preview_chat = gr.Markdown(label="Parquet ํŒŒ์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
 
274
  parquet_data_state = gr.State()
275
 
276
+ def handle_parquet_upload(file_path: str) -> Tuple[str, str, Dict]:
277
  message, parquet_content, parquet_json = upload_parquet(file_path)
278
  if parquet_json:
279
  return message, parquet_content, parquet_json
280
  else:
281
+ return message, "", {}
282
 
283
  parquet_upload_button.click(
284
  handle_parquet_upload,
 
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) -> Tuple[List[Dict[str, str]], str]:
 
 
 
295
  history = history or []
296
  history.append({"role": "user", "content": message})
 
 
297
  try:
298
+ # Parquet ๋ฐ์ดํ„ฐ๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋กœ์ง ์ถ”๊ฐ€ ๊ฐ€๋Šฅ
299
+ response_gen = respond(message, history, system_message, max_tokens, temperature, top_p)
300
+ response = ""
301
+ for partial in response_gen:
302
+ response = partial
303
  history.append({"role": "assistant", "content": response})
304
  except Exception as e:
305
+ response = f"์ถ”๋ก  ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
306
+ history.append({"role": "assistant", "content": response})
307
  return history, ""
308
 
309
  send_data_upload.click(
 
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():
320
+ text_input = gr.Textbox(
321
+ label="ํ…์ŠคํŠธ ์ž…๋ ฅ (๊ฐ ํ–‰์€ `id,text,label,metadata` ํ˜•์‹์œผ๋กœ ์ž…๋ ฅ)",
322
+ lines=10,
323
+ placeholder="์˜ˆ: 1,Sample Text,Label1,Metadata1\n2,Another Text,Label2,Metadata2"
324
+ )
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.Download(label="Parquet ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ")
329
 
330
+ def handle_text_to_parquet(text: str) -> Tuple[str, str, Tuple[bytes, str]]:
 
331
  message, parquet_content, file_data = text_to_parquet(text)
332
  if file_data:
333
+ filename = 'text_to_parquet.parquet'
334
+ return message, parquet_content, (file_data, filename)
335
  else:
336
  return message, "", None
337
 
 
341
  outputs=[convert_status, parquet_preview_convert, download_parquet_convert]
342
  )
343
 
344
+ # ์ฃผ์˜ ์‚ฌํ•ญ
345
  gr.Markdown("## ์ฃผ์˜ ์‚ฌํ•ญ")
346
  gr.Markdown("""
347
  - **CSV ์—…๋กœ๋“œ**: CSV ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜๋ฉด ์ž๋™์œผ๋กœ Parquet ํŒŒ์ผ๋กœ ๋ณ€ํ™˜๋ฉ๋‹ˆ๋‹ค. CSV ํŒŒ์ผ์€ ๋ฐ˜๋“œ์‹œ **์ฝค๋งˆ(`,`)**๋กœ ๊ตฌ๋ถ„๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
 
355
  gr.Markdown("### Gradio ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ LLM ๋ชจ๋ธ๊ณผ ์ƒํ˜ธ์ž‘์šฉํ•˜์„ธ์š”!")
356
 
357
  if __name__ == "__main__":
358
+ # share=True๋Š” Hugging Face Spaces์—์„œ ์ง€์›๋˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์ œ๊ฑฐ
359
+ demo.launch()