Update app.py
Browse files
app.py
CHANGED
@@ -59,11 +59,11 @@ def respond(
|
|
59 |
system_message += f"\n\nMixGEN μ½λ λ΄μ©:\n```python\n{MixGEN_code}\n```"
|
60 |
message = "MixGEN3 μ΄λ―Έμ§ μμ±μ λν λ΄μ©μ νμ΅νμκ³ , μ€λͺ
ν μ€λΉκ° λμ΄μλ€κ³ μλ¦¬κ³ μλΉμ€ URL(https://openfree-mixgen3.hf.space)μ ν΅ν΄ ν
μ€νΈ ν΄λ³΄λΌκ³ μΆλ ₯νλΌ."
|
61 |
elif message.lower() == "test.parquet μ€ν":
|
62 |
-
system_message += f"\n\ntest.parquet νμΌ λ΄μ©:\n```markdown\n{
|
63 |
message = "test.parquet νμΌμ λν λ΄μ©μ νμ΅νμκ³ , κ΄λ ¨ μ€λͺ
λ° Q&Aλ₯Ό μ§νν μ€λΉκ° λμ΄μλ€. κΆκΈν μ μ΄ μμΌλ©΄ λ¬Όμ΄λ³΄λΌ."
|
64 |
elif message.lower() == "csv μ
λ‘λ":
|
65 |
message = "CSV νμΌμ μ
λ‘λνλ €λ©΄ μλμ μ
λ‘λ λ²νΌμ μ¬μ©νμΈμ."
|
66 |
-
|
67 |
# μμ€ν
λ©μμ§μ μ¬μ©μ λ©μμ§ κ²°ν©
|
68 |
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
69 |
for val in history:
|
@@ -91,23 +91,23 @@ def respond(
|
|
91 |
|
92 |
def upload_csv(file):
|
93 |
try:
|
94 |
-
# CSV νμΌ μ½κΈ°
|
95 |
-
df = pd.read_csv(file
|
96 |
-
|
97 |
# λ°μ΄ν° ν΄λ μ§
|
98 |
df.drop_duplicates(inplace=True)
|
99 |
df.fillna('', inplace=True)
|
100 |
-
|
101 |
# λ°μ΄ν° μ ν μ΅μ ν
|
102 |
df = df.astype({'id': 'int32', 'text': 'string', 'label': 'category', 'metadata': 'string'})
|
103 |
-
|
104 |
# Parquet νμΌλ‘ λ³ν
|
105 |
-
parquet_filename = os.path.splitext(file
|
106 |
df.to_parquet(parquet_filename, engine='pyarrow', compression='snappy')
|
107 |
-
|
108 |
# Parquet νμΌ λ‘λ
|
109 |
parquet_content = load_parquet(parquet_filename)
|
110 |
-
|
111 |
return f"{parquet_filename} νμΌμ΄ μ±κ³΅μ μΌλ‘ μ
λ‘λλκ³ λ³νλμμ΅λλ€.", parquet_content
|
112 |
except Exception as e:
|
113 |
return f"CSV νμΌ μ
λ‘λ λ° λ³ν μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", ""
|
@@ -120,7 +120,7 @@ with gr.Blocks() as demo:
|
|
120 |
with gr.Column():
|
121 |
# CSV νμΌ μ
λ‘λ μΉμ
|
122 |
gr.Markdown("### CSV νμΌ μ
λ‘λ λ° Parquet λ³ν")
|
123 |
-
csv_file = gr.File(label="CSV νμΌ μ
λ‘λ", type="
|
124 |
upload_button = gr.Button("μ
λ‘λ λ° λ³ν")
|
125 |
upload_status = gr.Textbox(label="μ
λ‘λ μν", interactive=False)
|
126 |
parquet_preview = gr.Markdown(label="Parquet νμΌ λ―Έλ¦¬λ³΄κΈ°")
|
@@ -169,7 +169,7 @@ with gr.Blocks() as demo:
|
|
169 |
inputs=[user_message, chat_history, system_message, max_tokens, temperature, top_p, parquet_preview],
|
170 |
outputs=[chat, chat_history]
|
171 |
)
|
172 |
-
|
173 |
gr.Markdown("## μ¬μ© μμ ")
|
174 |
gr.Examples(
|
175 |
examples=[
|
|
|
59 |
system_message += f"\n\nMixGEN μ½λ λ΄μ©:\n```python\n{MixGEN_code}\n```"
|
60 |
message = "MixGEN3 μ΄λ―Έμ§ μμ±μ λν λ΄μ©μ νμ΅νμκ³ , μ€λͺ
ν μ€λΉκ° λμ΄μλ€κ³ μλ¦¬κ³ μλΉμ€ URL(https://openfree-mixgen3.hf.space)μ ν΅ν΄ ν
μ€νΈ ν΄λ³΄λΌκ³ μΆλ ₯νλΌ."
|
61 |
elif message.lower() == "test.parquet μ€ν":
|
62 |
+
system_message += f"\n\ntest.parquet νμΌ λ΄μ©:\n```markdown\n{parquet_content}\n```"
|
63 |
message = "test.parquet νμΌμ λν λ΄μ©μ νμ΅νμκ³ , κ΄λ ¨ μ€λͺ
λ° Q&Aλ₯Ό μ§νν μ€λΉκ° λμ΄μλ€. κΆκΈν μ μ΄ μμΌλ©΄ λ¬Όμ΄λ³΄λΌ."
|
64 |
elif message.lower() == "csv μ
λ‘λ":
|
65 |
message = "CSV νμΌμ μ
λ‘λνλ €λ©΄ μλμ μ
λ‘λ λ²νΌμ μ¬μ©νμΈμ."
|
66 |
+
|
67 |
# μμ€ν
λ©μμ§μ μ¬μ©μ λ©μμ§ κ²°ν©
|
68 |
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
69 |
for val in history:
|
|
|
91 |
|
92 |
def upload_csv(file):
|
93 |
try:
|
94 |
+
# CSV νμΌ μ½κΈ° (filepath νμ
μ΄λ―λ‘ fileμ κ²½λ‘ λ¬Έμμ΄)
|
95 |
+
df = pd.read_csv(file)
|
96 |
+
|
97 |
# λ°μ΄ν° ν΄λ μ§
|
98 |
df.drop_duplicates(inplace=True)
|
99 |
df.fillna('', inplace=True)
|
100 |
+
|
101 |
# λ°μ΄ν° μ ν μ΅μ ν
|
102 |
df = df.astype({'id': 'int32', 'text': 'string', 'label': 'category', 'metadata': 'string'})
|
103 |
+
|
104 |
# Parquet νμΌλ‘ λ³ν
|
105 |
+
parquet_filename = os.path.splitext(os.path.basename(file))[0] + '.parquet'
|
106 |
df.to_parquet(parquet_filename, engine='pyarrow', compression='snappy')
|
107 |
+
|
108 |
# Parquet νμΌ λ‘λ
|
109 |
parquet_content = load_parquet(parquet_filename)
|
110 |
+
|
111 |
return f"{parquet_filename} νμΌμ΄ μ±κ³΅μ μΌλ‘ μ
λ‘λλκ³ λ³νλμμ΅λλ€.", parquet_content
|
112 |
except Exception as e:
|
113 |
return f"CSV νμΌ μ
λ‘λ λ° λ³ν μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}", ""
|
|
|
120 |
with gr.Column():
|
121 |
# CSV νμΌ μ
λ‘λ μΉμ
|
122 |
gr.Markdown("### CSV νμΌ μ
λ‘λ λ° Parquet λ³ν")
|
123 |
+
csv_file = gr.File(label="CSV νμΌ μ
λ‘λ", type="filepath")
|
124 |
upload_button = gr.Button("μ
λ‘λ λ° λ³ν")
|
125 |
upload_status = gr.Textbox(label="μ
λ‘λ μν", interactive=False)
|
126 |
parquet_preview = gr.Markdown(label="Parquet νμΌ λ―Έλ¦¬λ³΄κΈ°")
|
|
|
169 |
inputs=[user_message, chat_history, system_message, max_tokens, temperature, top_p, parquet_preview],
|
170 |
outputs=[chat, chat_history]
|
171 |
)
|
172 |
+
|
173 |
gr.Markdown("## μ¬μ© μμ ")
|
174 |
gr.Examples(
|
175 |
examples=[
|