Update app.py
Browse files
app.py
CHANGED
@@ -35,9 +35,6 @@ MixGEN_code = load_code('mgen.cod')
|
|
35 |
# μ΄κΈ° Parquet νμΌ λ‘λ (κΈ°μ‘΄ test.parquet)
|
36 |
test_parquet_content = load_parquet('test.parquet')
|
37 |
|
38 |
-
# κΈλ‘λ² λ³μλ‘ Parquet λ΄μ© μ μ₯
|
39 |
-
current_parquet_content = test_parquet_content
|
40 |
-
|
41 |
def respond(
|
42 |
message,
|
43 |
history: List[Tuple[str, str]],
|
@@ -46,10 +43,9 @@ def respond(
|
|
46 |
temperature=0.7, # κΈ°λ³Έκ° μ μ§
|
47 |
top_p=0.9, # κΈ°λ³Έκ° μ μ§
|
48 |
):
|
49 |
-
|
50 |
-
system_message = system_message or ""
|
51 |
system_prefix = """λ°λμ νκΈλ‘ λ΅λ³ν κ². λλ μ£Όμ΄μ§ μμ€μ½λλ₯Ό κΈ°λ°μΌλ‘ "μλΉμ€ μ¬μ© μ€λͺ
λ° μλ΄, Q&Aλ₯Ό νλ μν μ΄λ€". μμ£Ό μΉμ νκ³ μμΈνκ² 4000ν ν° μ΄μ Markdown νμμΌλ‘ μμ±νλΌ. λλ μ½λλ₯Ό κΈ°λ°μΌλ‘ μ¬μ© μ€λͺ
λ° μ§μ μλ΅μ μ§ννλ©°, μ΄μ©μμκ² λμμ μ£Όμ΄μΌ νλ€. μ΄μ©μκ° κΆκΈν΄ ν λ§ν λ΄μ©μ μΉμ νκ² μλ €μ£Όλλ‘ νλΌ. μ½λ μ 체 λ΄μ©μ λν΄μλ 보μμ μ μ§νκ³ , ν€ κ° λ° μλν¬μΈνΈμ ꡬ체μ μΈ λͺ¨λΈμ 곡κ°νμ§ λ§λΌ."""
|
52 |
-
|
53 |
# λͺ
λ Ήμ΄ μ²λ¦¬
|
54 |
if message.lower() == "ν¨μ
μ½λ μ€ν":
|
55 |
system_message += f"\n\nν¨μ
μ½λ λ΄μ©:\n```python\n{fashion_code}\n```"
|
@@ -61,6 +57,8 @@ def respond(
|
|
61 |
system_message += f"\n\nMixGEN μ½λ λ΄μ©:\n```python\n{MixGEN_code}\n```"
|
62 |
message = "MixGEN3 μ΄λ―Έμ§ μμ±μ λν λ΄μ©μ νμ΅νμκ³ , μ€λͺ
ν μ€λΉκ° λμ΄μλ€κ³ μλ¦¬κ³ μλΉμ€ URL(https://openfree-mixgen3.hf.space)μ ν΅ν΄ ν
μ€νΈ ν΄λ³΄λΌκ³ μΆλ ₯νλΌ."
|
63 |
elif message.lower() == "test.parquet μ€ν":
|
|
|
|
|
64 |
system_message += f"\n\ntest.parquet νμΌ λ΄μ©:\n```markdown\n{current_parquet_content}\n```"
|
65 |
message = "test.parquet νμΌμ λν λ΄μ©μ νμ΅νμκ³ , κ΄λ ¨ μ€λͺ
λ° Q&Aλ₯Ό μ§νν μ€λΉκ° λμ΄μλ€. κΆκΈν μ μ΄ μμΌλ©΄ λ¬Όμ΄λ³΄λΌ."
|
66 |
elif message.lower() == "csv μ
λ‘λ":
|
@@ -102,7 +100,7 @@ def upload_csv(file):
|
|
102 |
missing_columns = required_columns - available_columns
|
103 |
|
104 |
if missing_columns:
|
105 |
-
return f"CSV νμΌμ λ€μ νμ 컬λΌμ΄ λλ½λμμ΅λλ€: {', '.join(missing_columns)}",
|
106 |
|
107 |
# λ°μ΄ν° ν΄λ μ§
|
108 |
df.drop_duplicates(inplace=True)
|
@@ -118,13 +116,21 @@ def upload_csv(file):
|
|
118 |
# Parquet νμΌ λ‘λ
|
119 |
parquet_content = load_parquet(parquet_filename)
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
-
return
|
126 |
except Exception as e:
|
127 |
-
return f"
|
128 |
|
129 |
# Gradio Blocks μΈν°νμ΄μ€ μ€μ
|
130 |
with gr.Blocks() as demo:
|
@@ -146,7 +152,7 @@ with gr.Blocks() as demo:
|
|
146 |
["νΉν μΆμμ νμ©ν κΈ°μ λ° λΉμ¦λμ€λͺ¨λΈ μΈ‘λ©΄μ ν¬ν¨νμ¬ νΉν μΆμμ ꡬμ±μ λ§κ² νμ μ μΈ μ°½μ λ°λͺ
λ΄μ©μ μ€μ¬μΌλ‘ 4000 ν ν° μ΄μ μμ±νλΌ."],
|
147 |
["κ³μ μ΄μ΄μ λ΅λ³νλΌ"],
|
148 |
],
|
149 |
-
theme="default", #
|
150 |
)
|
151 |
|
152 |
with gr.Accordion("μμ€ν
ν둬ννΈ λ° μ΅μ
μ€μ ", open=False):
|
@@ -159,26 +165,81 @@ with gr.Blocks() as demo:
|
|
159 |
gr.Markdown("### CSV νμΌ μ
λ‘λ λ° Parquet λ³ν")
|
160 |
with gr.Row():
|
161 |
with gr.Column():
|
162 |
-
csv_file = gr.File(label="CSV νμΌ μ
λ‘λ", type="
|
163 |
upload_button = gr.Button("μ
λ‘λ λ° λ³ν")
|
164 |
upload_status = gr.Textbox(label="μ
λ‘λ μν", interactive=False)
|
165 |
parquet_preview = gr.Markdown(label="Parquet νμΌ οΏ½οΏ½οΏ½λ¦¬λ³΄κΈ°")
|
166 |
-
|
|
|
167 |
# μ
λ‘λ λ²νΌ ν΄λ¦ μ μ€νν ν¨μ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
upload_button.click(
|
169 |
-
|
170 |
inputs=csv_file,
|
171 |
-
outputs=[upload_status, parquet_preview]
|
172 |
)
|
173 |
|
174 |
gr.Markdown("### κΈ°μ‘΄ Parquet νμΌ")
|
175 |
gr.Markdown(f"**test.parquet νμΌ λ΄μ©:**\n```markdown\n{test_parquet_content}\n```")
|
176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
gr.Markdown("## μ£Όμ μ¬ν")
|
178 |
gr.Markdown("""
|
179 |
- **CSV μ
λ‘λ**: CSV νμΌμ μ
λ‘λνλ©΄ μλμΌλ‘ Parquet νμΌλ‘ λ³νλ©λλ€. CSV νμΌμ λ°λμ **μ½€λ§(`,`)**λ‘ κ΅¬λΆλμ΄μΌ ν©λλ€.
|
180 |
- **Parquet 미리보기**: μ
λ‘λλ Parquet νμΌμ 첫 10κ° νμ΄ λ―Έλ¦¬λ³΄κΈ°λ‘ νμλ©λλ€.
|
181 |
- **LLMκ³Όμ λν**: λ³νλ Parquet νμΌ λ΄μ©μ κΈ°λ°μΌλ‘ LLMμ΄ μλ΅μ μμ±ν©λλ€.
|
|
|
|
|
182 |
""")
|
183 |
|
184 |
gr.Markdown("### Gradio μΈν°νμ΄μ€λ₯Ό μ¬μ©νμ¬ LLM λͺ¨λΈκ³Ό μνΈμμ©νμΈμ!")
|
|
|
35 |
# μ΄κΈ° Parquet νμΌ λ‘λ (κΈ°μ‘΄ test.parquet)
|
36 |
test_parquet_content = load_parquet('test.parquet')
|
37 |
|
|
|
|
|
|
|
38 |
def respond(
|
39 |
message,
|
40 |
history: List[Tuple[str, str]],
|
|
|
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```"
|
|
|
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 |
+
current_parquet_content = history.get('parquet_content', "")
|
62 |
system_message += f"\n\ntest.parquet νμΌ λ΄μ©:\n```markdown\n{current_parquet_content}\n```"
|
63 |
message = "test.parquet νμΌμ λν λ΄μ©μ νμ΅νμκ³ , κ΄λ ¨ μ€λͺ
λ° Q&Aλ₯Ό μ§νν μ€λΉκ° λμ΄μλ€. κΆκΈν μ μ΄ μμΌλ©΄ λ¬Όμ΄λ³΄λΌ."
|
64 |
elif message.lower() == "csv μ
λ‘λ":
|
|
|
100 |
missing_columns = required_columns - available_columns
|
101 |
|
102 |
if missing_columns:
|
103 |
+
return f"CSV νμΌμ λ€μ νμ 컬λΌμ΄ λλ½λμμ΅λλ€: {', '.join(missing_columns)}", None
|
104 |
|
105 |
# λ°μ΄ν° ν΄λ μ§
|
106 |
df.drop_duplicates(inplace=True)
|
|
|
116 |
# Parquet νμΌ λ‘λ
|
117 |
parquet_content = load_parquet(parquet_filename)
|
118 |
|
119 |
+
return f"{parquet_filename} νμΌμ΄ μ±κ³΅μ μΌλ‘ μ
λ‘λλκ³ λ³νλμμ΅λλ€.", parquet_filename
|
120 |
+
except Exception as e:
|
121 |
+
return f"CSV νμΌ μ
λ‘λ λ° λ³ν μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", None
|
122 |
+
|
123 |
+
def upload_parquet(file):
|
124 |
+
try:
|
125 |
+
# Parquet νμΌ μ½κΈ°
|
126 |
+
df = pd.read_parquet(file, engine='pyarrow')
|
127 |
+
|
128 |
+
# λ°μ΄ν°νλ μμ MarkdownμΌλ‘ λ³ν
|
129 |
+
parquet_content = df.to_markdown(index=False)
|
130 |
|
131 |
+
return "Parquet νμΌμ΄ μ±κ³΅μ μΌλ‘ μ
λ‘λλμμ΅λλ€.", parquet_content, df.to_json() # JSONμΌλ‘ λ°μ΄ν° μ μ₯
|
132 |
except Exception as e:
|
133 |
+
return f"Parquet νμΌ μ
λ‘λ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", None, None
|
134 |
|
135 |
# Gradio Blocks μΈν°νμ΄μ€ μ€μ
|
136 |
with gr.Blocks() as demo:
|
|
|
152 |
["νΉν μΆμμ νμ©ν κΈ°μ λ° λΉμ¦λμ€λͺ¨λΈ μΈ‘λ©΄μ ν¬ν¨νμ¬ νΉν μΆμμ ꡬμ±μ λ§κ² νμ μ μΈ μ°½μ λ°λͺ
λ΄μ©μ μ€μ¬μΌλ‘ 4000 ν ν° μ΄μ μμ±νλΌ."],
|
153 |
["κ³μ μ΄μ΄μ λ΅λ³νλΌ"],
|
154 |
],
|
155 |
+
theme="default", # μνλ ν
λ§λ‘ λ³κ²½ κ°λ₯
|
156 |
)
|
157 |
|
158 |
with gr.Accordion("μμ€ν
ν둬ννΈ λ° μ΅μ
μ€μ ", open=False):
|
|
|
165 |
gr.Markdown("### CSV νμΌ μ
λ‘λ λ° Parquet λ³ν")
|
166 |
with gr.Row():
|
167 |
with gr.Column():
|
168 |
+
csv_file = gr.File(label="CSV νμΌ μ
λ‘λ", type="file")
|
169 |
upload_button = gr.Button("μ
λ‘λ λ° λ³ν")
|
170 |
upload_status = gr.Textbox(label="μ
λ‘λ μν", interactive=False)
|
171 |
parquet_preview = gr.Markdown(label="Parquet νμΌ οΏ½οΏ½οΏ½λ¦¬λ³΄κΈ°")
|
172 |
+
download_button = gr.File(label="Parquet νμΌ λ€μ΄λ‘λ", file=None, interactive=False)
|
173 |
+
|
174 |
# μ
λ‘λ λ²νΌ ν΄λ¦ μ μ€νν ν¨μ
|
175 |
+
def handle_csv_upload(file):
|
176 |
+
message, parquet_filename = upload_csv(file.name)
|
177 |
+
if parquet_filename:
|
178 |
+
# νμΌμ λ€μ΄λ‘λν μ μλλ‘ κ²½λ‘ μ€μ
|
179 |
+
with open(parquet_filename, "rb") as f:
|
180 |
+
data = f.read()
|
181 |
+
return message, parquet_preview.update(value=load_parquet(parquet_filename)), gr.File.update(value=(parquet_filename, data))
|
182 |
+
else:
|
183 |
+
return message, "", None
|
184 |
+
|
185 |
upload_button.click(
|
186 |
+
handle_csv_upload,
|
187 |
inputs=csv_file,
|
188 |
+
outputs=[upload_status, parquet_preview, download_button]
|
189 |
)
|
190 |
|
191 |
gr.Markdown("### κΈ°μ‘΄ Parquet νμΌ")
|
192 |
gr.Markdown(f"**test.parquet νμΌ λ΄μ©:**\n```markdown\n{test_parquet_content}\n```")
|
193 |
|
194 |
+
with gr.Tab("μ±λ΄"):
|
195 |
+
gr.Markdown("### Parquet νμΌ μ
λ‘λ λ° μ§λ¬ΈνκΈ°")
|
196 |
+
with gr.Row():
|
197 |
+
with gr.Column():
|
198 |
+
parquet_upload = gr.File(label="Parquet νμΌ μ
λ‘λ", type="file")
|
199 |
+
parquet_upload_button = gr.Button("μ
λ‘λ")
|
200 |
+
parquet_upload_status = gr.Textbox(label="μ
λ‘λ μν", interactive=False)
|
201 |
+
parquet_preview_chat = gr.Markdown(label="Parquet νμΌ λ―Έλ¦¬λ³΄κΈ°")
|
202 |
+
# μνλ₯Ό μ μ₯ν Hidden State
|
203 |
+
parquet_data_state = gr.State()
|
204 |
+
|
205 |
+
def handle_parquet_upload(file):
|
206 |
+
message, parquet_content, parquet_json = upload_parquet(file.name)
|
207 |
+
if parquet_json:
|
208 |
+
return message, parquet_preview_chat.update(value=parquet_content), parquet_data_state.update(value=parquet_json)
|
209 |
+
else:
|
210 |
+
return message, gr.Markdown.update(value=""), parquet_data_state.update(value=None)
|
211 |
+
|
212 |
+
parquet_upload_button.click(
|
213 |
+
handle_parquet_upload,
|
214 |
+
inputs=parquet_upload,
|
215 |
+
outputs=[parquet_upload_status, parquet_preview_chat, parquet_data_state]
|
216 |
+
)
|
217 |
+
|
218 |
+
gr.Markdown("### LLMκ³Ό λννκΈ°")
|
219 |
+
chat_interface = gr.ChatInterface(
|
220 |
+
fn=respond,
|
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 |
+
theme="default", # μνλ ν
λ§λ‘ λ³κ²½ κ°λ₯
|
234 |
+
)
|
235 |
+
|
236 |
gr.Markdown("## μ£Όμ μ¬ν")
|
237 |
gr.Markdown("""
|
238 |
- **CSV μ
λ‘λ**: CSV νμΌμ μ
λ‘λνλ©΄ μλμΌλ‘ Parquet νμΌλ‘ λ³νλ©λλ€. CSV νμΌμ λ°λμ **μ½€λ§(`,`)**λ‘ κ΅¬λΆλμ΄μΌ ν©λλ€.
|
239 |
- **Parquet 미리보기**: μ
λ‘λλ Parquet νμΌμ 첫 10κ° νμ΄ λ―Έλ¦¬λ³΄κΈ°λ‘ νμλ©λλ€.
|
240 |
- **LLMκ³Όμ λν**: λ³νλ Parquet νμΌ λ΄μ©μ κΈ°λ°μΌλ‘ LLMμ΄ μλ΅μ μμ±ν©λλ€.
|
241 |
+
- **Parquet λ€μ΄λ‘λ**: λ³νλ Parquet νμΌμ λ€μ΄λ‘λνλ €λ©΄ λ³νλ νμΌ μμ λ€μ΄λ‘λ λ§ν¬λ₯Ό ν΄λ¦νμΈμ.
|
242 |
+
- **μ±λ΄ Parquet μ
λ‘λ**: μ±λ΄ νμμ Parquet νμΌμ μ
λ‘λνλ©΄ ν΄λΉ λ°μ΄ν°λ₯Ό κΈ°λ°μΌλ‘ μ§λ¬Έκ³Ό λ΅λ³μ μ§νν μ μμ΅λλ€.
|
243 |
""")
|
244 |
|
245 |
gr.Markdown("### Gradio μΈν°νμ΄μ€λ₯Ό μ¬μ©νμ¬ LLM λͺ¨λΈκ³Ό μνΈμμ©νμΈμ!")
|