File size: 16,218 Bytes
747ccea
 
fe67895
90e9b67
da419ba
f779047
54a4802
e74c3bc
90e9b67
0e5afe0
c36dc6b
6da265e
c36dc6b
6da265e
 
c36dc6b
6da265e
 
 
90e9b67
 
 
c3ae439
 
90e9b67
 
 
 
 
 
c36dc6b
 
de57dc5
6da265e
4f42976
90e9b67
 
747ccea
 
f6e3821
ff1c374
71edfae
 
 
 
ca69132
c3ae439
ca69132
4f42976
6da265e
c3ae439
54e6271
c36dc6b
c3ae439
54e6271
da419ba
c3ae439
c3d05ea
90e9b67
f6e3821
95a32d4
 
f6e3821
 
95a32d4
 
90e9b67
4f42976
884361c
ea2c4cf
4f42976
da419ba
f6e3821
 
747ccea
 
91c1d45
90e9b67
4f42976
90e9b67
 
 
 
 
 
4f42976
90e9b67
c3ae439
90e9b67
 
 
8321675
f6e3821
4f42976
71edfae
f6e3821
ea2c4cf
884361c
 
 
 
 
 
ca69132
884361c
4f42976
 
 
ea2c4cf
4f42976
 
ea2c4cf
4f42976
f6e3821
4f42976
ea2c4cf
4f42976
 
ea2c4cf
ca69132
 
 
 
f6e3821
ca69132
 
f6e3821
ca69132
 
 
884361c
ca69132
4f42976
ca69132
4f42976
f6e3821
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66fa514
 
 
 
f6e3821
 
 
 
 
 
66fa514
 
4f42976
66fa514
4f42976
884361c
 
 
f6e3821
2013128
 
884361c
71edfae
95a32d4
71edfae
 
 
 
2013128
 
 
 
f6e3821
2013128
 
 
 
 
 
f6e3821
2013128
f6e3821
2013128
 
 
 
 
 
 
 
884361c
 
 
 
95a32d4
884361c
 
 
2013128
ca69132
884361c
f6e3821
 
ca69132
f6e3821
ca69132
 
f6e3821
ca69132
 
 
884361c
ca69132
884361c
ca69132
884361c
4f42976
884361c
 
 
95a32d4
ca69132
 
 
95a32d4
ca69132
 
 
 
 
 
f6e3821
 
ca69132
 
 
 
 
 
 
 
 
 
f6e3821
ca69132
f6e3821
2013128
 
 
 
 
 
 
f6e3821
2013128
 
 
 
 
 
f6e3821
2013128
f6e3821
2013128
 
 
 
 
 
ca69132
 
f6e3821
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4f42976
 
71edfae
4f42976
 
ca69132
95a32d4
f6e3821
4f42976
884361c
4f42976
747ccea
 
90e9b67
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
import gradio as gr
from huggingface_hub import InferenceClient
import os
import pandas as pd
from typing import List, Tuple

# μΆ”λ‘  API ν΄λΌμ΄μ–ΈνŠΈ μ„€μ •
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=os.getenv("HF_TOKEN"))
# hf_client = InferenceClient("CohereForAI/aya-23-35B", token=os.getenv("HF_TOKEN"))

def load_code(filename):
    try:
        with open(filename, 'r', encoding='utf-8') as file:
            return file.read()
    except FileNotFoundError:
        return f"{filename} νŒŒμΌμ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€."
    except Exception as e:
        return f"νŒŒμΌμ„ μ½λŠ” 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"

def load_parquet(filename):
    try:
        df = pd.read_parquet(filename, engine='pyarrow')
        # λ°μ΄ν„°ν”„λ ˆμž„μ˜ 첫 λͺ‡ 행을 λ¬Έμžμ—΄λ‘œ λ³€ν™˜ (Markdown ν‘œ ν˜•μ‹)
        return df.head(10).to_markdown(index=False)
    except FileNotFoundError:
        return f"{filename} νŒŒμΌμ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€."
    except Exception as e:
        return f"νŒŒμΌμ„ μ½λŠ” 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"

# μ½”λ“œ 파일 λ‘œλ“œ
fashion_code = load_code('fashion.cod')
uhdimage_code = load_code('uhdimage.cod')
MixGEN_code = load_code('mgen.cod')

# 초기 Parquet 파일 λ‘œλ“œ (κΈ°μ‘΄ test.parquet)
test_parquet_content = load_parquet('test.parquet')

def respond(
    message,
    history: List[dict],
    system_message="",  # κΈ°λ³Έκ°’ μΆ”κ°€
    max_tokens=4000,    # κΈ°λ³Έκ°’ λ³€κ²½
    temperature=0.7,    # κΈ°λ³Έκ°’ μœ μ§€
    top_p=0.9,           # κΈ°λ³Έκ°’ μœ μ§€
    ):
    # μ‹œμŠ€ν…œ ν”„λ‘¬ν”„νŠΈ μ„€μ •
    system_prefix = """λ°˜λ“œμ‹œ ν•œκΈ€λ‘œ 닡변할것. λ„ˆλŠ” 주어진 μ†ŒμŠ€μ½”λ“œλ₯Ό 기반으둜 "μ„œλΉ„μŠ€ μ‚¬μš© μ„€λͺ… 및 μ•ˆλ‚΄, Q&Aλ₯Ό ν•˜λŠ” 역할이닀". μ•„μ£Ό μΉœμ ˆν•˜κ³  μžμ„Έν•˜κ²Œ 4000토큰 이상 Markdown ν˜•μ‹μœΌλ‘œ μž‘μ„±ν•˜λΌ. λ„ˆλŠ” μ½”λ“œλ₯Ό 기반으둜 μ‚¬μš© μ„€λͺ… 및 질의 응닡을 μ§„ν–‰ν•˜λ©°, μ΄μš©μžμ—κ²Œ 도움을 μ£Όμ–΄μ•Ό ν•œλ‹€. μ΄μš©μžκ°€ κΆκΈˆν•΄ ν•  λ§Œν•œ λ‚΄μš©μ— μΉœμ ˆν•˜κ²Œ μ•Œλ €μ£Όλ„λ‘ ν•˜λΌ. μ½”λ“œ 전체 λ‚΄μš©μ— λŒ€ν•΄μ„œλŠ” λ³΄μ•ˆμ„ μœ μ§€ν•˜κ³ , ν‚€ κ°’ 및 μ—”λ“œν¬μΈνŠΈμ™€ ꡬ체적인 λͺ¨λΈμ€ κ³΅κ°œν•˜μ§€ 마라."""
    
    # λͺ…λ Ήμ–΄ 처리
    if message.lower() == "νŒ¨μ…˜ μ½”λ“œ μ‹€ν–‰":
        system_message += f"\n\nνŒ¨μ…˜ μ½”λ“œ λ‚΄μš©:\n```python\n{fashion_code}\n```"
        message = "νŒ¨μ…˜ κ°€μƒν”ΌνŒ…μ— λŒ€ν•œ λ‚΄μš©μ„ ν•™μŠ΅ν•˜μ˜€κ³ , μ„€λͺ…ν•  μ€€λΉ„κ°€ λ˜μ–΄μžˆλ‹€κ³  μ•Œλ¦¬κ³  μ„œλΉ„μŠ€ URL(https://aiqcamp-fash.hf.space)을 톡해 ν…ŒμŠ€νŠΈ 해보라고 좜λ ₯ν•˜λΌ."
    elif message.lower() == "uhd 이미지 μ½”λ“œ μ‹€ν–‰":
        system_message += f"\n\nUHD 이미지 μ½”λ“œ λ‚΄μš©:\n```python\n{uhdimage_code}\n```"
        message = "UHD 이미지 생성에 λŒ€ν•œ λ‚΄μš©μ„ ν•™μŠ΅ν•˜μ˜€κ³ , μ„€λͺ…ν•  μ€€λΉ„κ°€ λ˜μ–΄μžˆλ‹€κ³  μ•Œλ¦¬κ³  μ„œλΉ„μŠ€ URL(https://openfree-ultpixgen.hf.space)을 톡해 ν…ŒμŠ€νŠΈ 해보라고 좜λ ₯ν•˜λΌ."
    elif message.lower() == "mixgen μ½”λ“œ μ‹€ν–‰":
        system_message += f"\n\nMixGEN μ½”λ“œ λ‚΄μš©:\n```python\n{MixGEN_code}\n```"
        message = "MixGEN3 이미지 생성에 λŒ€ν•œ λ‚΄μš©μ„ ν•™μŠ΅ν•˜μ˜€κ³ , μ„€λͺ…ν•  μ€€λΉ„κ°€ λ˜μ–΄μžˆλ‹€κ³  μ•Œλ¦¬κ³  μ„œλΉ„μŠ€ URL(https://openfree-mixgen3.hf.space)을 톡해 ν…ŒμŠ€νŠΈ 해보라고 좜λ ₯ν•˜λΌ."
    elif message.lower() == "test.parquet μ‹€ν–‰":
        # Parquet λ‚΄μš© μ°Έμ‘°
        parquet_content = ""
        for item in history:
            if item['role'] == 'assistant' and 'test.parquet 파일 λ‚΄μš©' in item['content']:
                parquet_content = item['content'].split("```markdown\n")[1].split("\n```")[0]
                break
        system_message += f"\n\ntest.parquet 파일 λ‚΄μš©:\n```markdown\n{parquet_content}\n```"
        message = "test.parquet νŒŒμΌμ— λŒ€ν•œ λ‚΄μš©μ„ ν•™μŠ΅ν•˜μ˜€κ³ , κ΄€λ ¨ μ„€λͺ… 및 Q&Aλ₯Ό 진행할 μ€€λΉ„κ°€ λ˜μ–΄μžˆλ‹€. κΆκΈˆν•œ 점이 있으면 물어보라."
    elif message.lower() == "csv μ—…λ‘œλ“œ":
        message = "CSV νŒŒμΌμ„ μ—…λ‘œλ“œν•˜λ €λ©΄ 두 번째 탭을 μ‚¬μš©ν•˜μ„Έμš”."

    # μ‹œμŠ€ν…œ λ©”μ‹œμ§€μ™€ μ‚¬μš©μž λ©”μ‹œμ§€ κ²°ν•©
    messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
    for chat in history:
        messages.append({"role": chat['role'], "content": chat['content']})
    messages.append({"role": "user", "content": message})

    response = ""
    try:
        for msg in hf_client.chat_completion(
            messages,
            max_tokens=max_tokens,
            stream=True,
            temperature=temperature,
            top_p=top_p,
        ):
            token = msg.choices[0].delta.get('content', None)
            if token:
                response += token
                yield response
    except Exception as e:
        yield f"μΆ”λ‘  쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"

def upload_csv(file_path):
    try:
        # CSV 파일 읽기 (κ΅¬λΆ„μž 콀마)
        df = pd.read_csv(file_path, sep=',')

        # CSV 파일의 컬럼 확인
        required_columns = {'id', 'text', 'label', 'metadata'}
        available_columns = set(df.columns)
        missing_columns = required_columns - available_columns

        if missing_columns:
            return f"CSV νŒŒμΌμ— λ‹€μŒ ν•„μˆ˜ 컬럼이 λˆ„λ½λ˜μ—ˆμŠ΅λ‹ˆλ‹€: {', '.join(missing_columns)}", None

        # 데이터 ν΄λ Œμ§•
        df.drop_duplicates(inplace=True)
        df.fillna('', inplace=True)

        # 데이터 μœ ν˜• μ΅œμ ν™”
        df = df.astype({'id': 'int32', 'text': 'string', 'label': 'category', 'metadata': 'string'})

        # Parquet 파일둜 λ³€ν™˜
        parquet_filename = os.path.splitext(os.path.basename(file_path))[0] + '.parquet'
        df.to_parquet(parquet_filename, engine='pyarrow', compression='snappy')

        # Parquet 파일 λ‘œλ“œ
        parquet_content = load_parquet(parquet_filename)

        return f"{parquet_filename} 파일이 μ„±κ³΅μ μœΌλ‘œ μ—…λ‘œλ“œλ˜κ³  λ³€ν™˜λ˜μ—ˆμŠ΅λ‹ˆλ‹€.", parquet_filename
    except Exception as e:
        return f"CSV 파일 μ—…λ‘œλ“œ 및 λ³€ν™˜ 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}", None

def upload_parquet(file_path):
    try:
        # Parquet 파일 읽기
        df = pd.read_parquet(file_path, engine='pyarrow')

        # λ°μ΄ν„°ν”„λ ˆμž„μ„ Markdown으둜 λ³€ν™˜
        parquet_content = df.to_markdown(index=False)

        return "Parquet 파일이 μ„±κ³΅μ μœΌλ‘œ μ—…λ‘œλ“œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.", parquet_content, df.to_json()  # JSON으둜 데이터 μ €μž₯
    except Exception as e:
        return f"Parquet 파일 μ—…λ‘œλ“œ 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}", None, None

def text_to_parquet(text):
    try:
        # ν…μŠ€νŠΈλ₯Ό DataFrame으둜 λ³€ν™˜ (μ˜ˆμ‹œ: 각 쀄을 μƒˆλ‘œμš΄ ν–‰μœΌλ‘œ)
        data = [line.split(',') for line in text.strip().split('\n')]
        df = pd.DataFrame(data, columns=['id', 'text', 'label', 'metadata'])

        # Parquet 파일둜 λ³€ν™˜
        parquet_filename = 'text_to_parquet.parquet'
        df.to_parquet(parquet_filename, engine='pyarrow', compression='snappy')

        # Parquet 파일 λ‘œλ“œ
        parquet_content = load_parquet(parquet_filename)

        # 파일 데이터λ₯Ό 읽어 λ°”μ΄λ„ˆλ¦¬λ‘œ λ°˜ν™˜
        with open(parquet_filename, "rb") as f:
            data = f.read()

        return f"{parquet_filename} 파일이 μ„±κ³΅μ μœΌλ‘œ λ³€ν™˜λ˜μ—ˆμŠ΅λ‹ˆλ‹€.", parquet_content, (parquet_filename, data)
    except Exception as e:
        return f"ν…μŠ€νŠΈ λ³€ν™˜ 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}", "", None

css = """
footer {
    visibility: hidden;
}
.chatbot-container {
    height: 600px;
}
.chatbot-container .message {
    font-size: 14px;
}
"""

# Gradio Blocks μΈν„°νŽ˜μ΄μŠ€ μ„€μ •
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
    gr.Markdown("# LLM μ„œλΉ„μŠ€ μΈν„°νŽ˜μ΄μŠ€")

    with gr.Tab("챗봇"):
        gr.Markdown("### LLMκ³Ό λŒ€ν™”ν•˜κΈ°")
        chatbot = gr.Chatbot(label="챗봇", elem_id="chatbot-container")
        msg = gr.Textbox(label="λ©”μ‹œμ§€ μž…λ ₯")
        send = gr.Button("전솑")

        with gr.Accordion("μ‹œμŠ€ν…œ ν”„λ‘¬ν”„νŠΈ 및 μ˜΅μ…˜ μ„€μ •", open=False):
            system_message = gr.Textbox(label="System Message", value="λ„ˆλŠ” AI μ‘°μ–Έμž 역할이닀.")
            max_tokens = gr.Slider(minimum=1, maximum=8000, value=4000, label="Max Tokens")
            temperature = gr.Slider(minimum=0, maximum=1, value=0.7, label="Temperature")
            top_p = gr.Slider(minimum=0, maximum=1, value=0.9, label="Top P")

        # 챗봇 λ©”μ‹œμ§€ 처리 ν•¨μˆ˜
        def handle_message(message, history, system_message, max_tokens, temperature, top_p):
            # Update history with user message
            history = history or []
            history.append({"role": "user", "content": message})
            # Generate response
            response = ""
            try:
                for token in respond(message, history, system_message, max_tokens, temperature, top_p):
                    response = token
                # Update history with assistant response
                history.append({"role": "assistant", "content": response})
            except Exception as e:
                history.append({"role": "assistant", "content": f"μΆ”λ‘  쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"})
            return history, ""

        send.click(
            handle_message,
            inputs=[msg, chatbot, system_message, max_tokens, temperature, top_p],
            outputs=[chatbot, msg]
        )

    with gr.Tab("데이터 λ³€ν™˜"):
        gr.Markdown("### CSV 파일 μ—…λ‘œλ“œ 및 Parquet λ³€ν™˜")
        with gr.Row():
            with gr.Column():
                csv_file = gr.File(label="CSV 파일 μ—…λ‘œλ“œ", type="filepath")
                upload_button = gr.Button("μ—…λ‘œλ“œ 및 λ³€ν™˜")
                upload_status = gr.Textbox(label="μ—…λ‘œλ“œ μƒνƒœ", interactive=False)
                parquet_preview = gr.Markdown(label="Parquet 파일 미리보기")
                download_button = gr.File(label="Parquet 파일 λ‹€μš΄λ‘œλ“œ", type="binary", interactive=False)

                # μ—…λ‘œλ“œ λ²„νŠΌ 클릭 μ‹œ μ‹€ν–‰ν•  ν•¨μˆ˜
                def handle_csv_upload(file_path):
                    message, parquet_filename = upload_csv(file_path)
                    if parquet_filename:
                        # νŒŒμΌμ„ λ‹€μš΄λ‘œλ“œν•  수 μžˆλ„λ‘ λ°”μ΄λ„ˆλ¦¬ λ°μ΄ν„°λ‘œ 읽기
                        with open(parquet_filename, "rb") as f:
                            data = f.read()
                        return message, load_parquet(parquet_filename), (parquet_filename, data)
                    else:
                        return message, "", None

                upload_button.click(
                    handle_csv_upload,
                    inputs=csv_file,
                    outputs=[upload_status, parquet_preview, download_button]
                )
        
        gr.Markdown("### 기쑴 Parquet 파일")
        gr.Markdown(f"**test.parquet 파일 λ‚΄μš©:**\n```markdown\n{test_parquet_content}\n```")

    with gr.Tab("챗봇 데이터 μ—…λ‘œλ“œ"):
        gr.Markdown("### Parquet 파일 μ—…λ‘œλ“œ 및 μ§ˆλ¬Έν•˜κΈ°")
        with gr.Row():
            with gr.Column():
                parquet_upload = gr.File(label="Parquet 파일 μ—…λ‘œλ“œ", type="filepath")
                parquet_upload_button = gr.Button("μ—…λ‘œλ“œ")
                parquet_upload_status = gr.Textbox(label="μ—…λ‘œλ“œ μƒνƒœ", interactive=False)
                parquet_preview_chat = gr.Markdown(label="Parquet 파일 미리보기")
                # μƒνƒœλ₯Ό μ €μž₯ν•  Hidden State
                parquet_data_state = gr.State()

                def handle_parquet_upload(file_path):
                    message, parquet_content, parquet_json = upload_parquet(file_path)
                    if parquet_json:
                        return message, parquet_preview_chat.update(value=parquet_content), parquet_data_state.update(value=parquet_json)
                    else:
                        return message, gr.Markdown.update(value=""), parquet_data_state.update(value=None)

                parquet_upload_button.click(
                    handle_parquet_upload,
                    inputs=parquet_upload,
                    outputs=[parquet_upload_status, parquet_preview_chat, parquet_data_state]
                )
        
        gr.Markdown("### LLMκ³Ό λŒ€ν™”ν•˜κΈ°")
        chatbot_data_upload = gr.Chatbot(label="챗봇 데이터 μ—…λ‘œλ“œ", elem_id="chatbot-data-upload")
        msg_data_upload = gr.Textbox(label="λ©”μ‹œμ§€ μž…λ ₯")
        send_data_upload = gr.Button("전솑")

        # 챗봇 λ©”μ‹œμ§€ 처리 ν•¨μˆ˜ (데이터 μ—…λ‘œλ“œ 버전)
        def handle_message_data_upload(message, history, system_message, max_tokens, temperature, top_p, parquet_data):
            # Update history with user message
            history = history or []
            history.append({"role": "user", "content": message})
            # Generate response
            response = ""
            try:
                for token in respond(message, history, system_message, max_tokens, temperature, top_p):
                    response = token
                # Update history with assistant response
                history.append({"role": "assistant", "content": response})
            except Exception as e:
                history.append({"role": "assistant", "content": f"μΆ”λ‘  쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"})
            return history, ""

        send_data_upload.click(
            handle_message_data_upload,
            inputs=[msg_data_upload, chatbot_data_upload, system_message, max_tokens, temperature, top_p, parquet_data_state],
            outputs=[chatbot_data_upload, msg_data_upload]
        )

    with gr.Tab("ν…μŠ€νŠΈ to csv to parquet λ³€ν™”"):
        gr.Markdown("### ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜λ©΄ CSV둜 λ³€ν™˜ ν›„ Parquet으둜 μžλ™ μ „ν™˜λ©λ‹ˆλ‹€.")
        with gr.Row():
            with gr.Column():
                text_input = gr.Textbox(label="ν…μŠ€νŠΈ μž…λ ₯ (각 행은 `id,text,label,metadata` ν˜•μ‹μœΌλ‘œ μž…λ ₯)", lines=10)
                convert_button = gr.Button("λ³€ν™˜ 및 λ‹€μš΄λ‘œλ“œ")
                convert_status = gr.Textbox(label="λ³€ν™˜ μƒνƒœ", interactive=False)
                parquet_preview_convert = gr.Markdown(label="Parquet 파일 미리보기")
                download_parquet_convert = gr.File(label="Parquet 파일 λ‹€μš΄λ‘œλ“œ", type="binary", interactive=False)

                def handle_text_to_parquet(text):
                    message, parquet_content, file_data = text_to_parquet(text)
                    if file_data:
                        return message, parquet_content, file_data
                    else:
                        return message, "", None

                convert_button.click(
                    handle_text_to_parquet,
                    inputs=text_input,
                    outputs=[convert_status, parquet_preview_convert, download_parquet_convert]
                )

    gr.Markdown("## 주의 사항")
    gr.Markdown("""
    - **CSV μ—…λ‘œλ“œ**: CSV νŒŒμΌμ„ μ—…λ‘œλ“œν•˜λ©΄ μžλ™μœΌλ‘œ Parquet 파일둜 λ³€ν™˜λ©λ‹ˆλ‹€. CSV νŒŒμΌμ€ λ°˜λ“œμ‹œ **콀마(`,`)**둜 κ΅¬λΆ„λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€.
    - **Parquet 미리보기**: μ—…λ‘œλ“œλœ Parquet 파일의 첫 10개 행이 미리보기둜 ν‘œμ‹œλ©λ‹ˆλ‹€.
    - **LLM과의 λŒ€ν™”**: λ³€ν™˜λœ Parquet 파일 λ‚΄μš©μ„ 기반으둜 LLM이 응닡을 μƒμ„±ν•©λ‹ˆλ‹€.
    - **Parquet λ‹€μš΄λ‘œλ“œ**: λ³€ν™˜λœ Parquet νŒŒμΌμ„ λ‹€μš΄λ‘œλ“œν•˜λ €λ©΄ λ³€ν™˜λœ 파일 μ˜†μ˜ λ‹€μš΄λ‘œλ“œ 링크λ₯Ό ν΄λ¦­ν•˜μ„Έμš”.
    - **챗봇 데이터 μ—…λ‘œλ“œ**: 챗봇 데이터 μ—…λ‘œλ“œ νƒ­μ—μ„œ Parquet νŒŒμΌμ„ μ—…λ‘œλ“œν•˜λ©΄ ν•΄λ‹Ή 데이터λ₯Ό 기반으둜 질문과 닡변을 진행할 수 μžˆμŠ΅λ‹ˆλ‹€.
    - **ν…μŠ€νŠΈ to csv to parquet**: λ„€ 번째 νƒ­μ—μ„œ ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜λ©΄ μžλ™μœΌλ‘œ CSV둜 λ³€ν™˜λ˜κ³ , λ‹€μ‹œ Parquet 파일둜 μ „ν™˜λ˜μ–΄ λ‹€μš΄λ‘œλ“œν•  수 μžˆμŠ΅λ‹ˆλ‹€.
    """)

    gr.Markdown("### Gradio μΈν„°νŽ˜μ΄μŠ€λ₯Ό μ‚¬μš©ν•˜μ—¬ LLM λͺ¨λΈκ³Ό μƒν˜Έμž‘μš©ν•˜μ„Έμš”!")

if __name__ == "__main__":
    demo.launch()