Update app.py
Browse files
app.py
CHANGED
|
@@ -22,6 +22,14 @@ def read_uploaded_file(file):
|
|
| 22 |
except Exception as e:
|
| 23 |
return f"νμΌμ μ½λ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def chat(message, history, uploaded_file, system_message="", max_tokens=4000, temperature=0.7, top_p=0.9):
|
| 26 |
system_prefix = """λ°λμ νκΈλ‘ λ΅λ³ν κ². λλ μ£Όμ΄μ§ μμ€μ½λλ λ°μ΄ν°λ₯Ό κΈ°λ°μΌλ‘ "μλΉμ€ μ¬μ© μ€λͺ
λ° μλ΄, Q&Aλ₯Ό νλ μν μ΄λ€". μμ£Ό μΉμ νκ³ μμΈνκ² 4000ν ν° μ΄μ Markdown νμμΌλ‘ μμ±νλΌ. λλ μ
λ ₯λ λ΄μ©μ κΈ°λ°μΌλ‘ μ¬μ© μ€λͺ
λ° μ§μ μλ΅μ μ§ννλ©°, μ΄μ©μμκ² λμμ μ£Όμ΄μΌ νλ€. μ΄μ©μκ° κΆκΈν΄ ν λ§ν λ΄μ©μ μΉμ νκ² μλ €μ£Όλλ‘ νλΌ. μ 체 λ΄μ©μ λν΄μλ 보μμ μ μ§νκ³ , ν€ κ° λ° μλν¬μΈνΈμ ꡬ체μ μΈ λͺ¨λΈμ 곡κ°νμ§ λ§λΌ."""
|
| 27 |
|
|
@@ -43,11 +51,7 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
|
|
| 43 |
5. κΈ°λν¨κ³Ό λ° μ₯μ """
|
| 44 |
|
| 45 |
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
| 46 |
-
|
| 47 |
-
if val[0]:
|
| 48 |
-
messages.append({"role": "user", "content": val[0]})
|
| 49 |
-
if val[1]:
|
| 50 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 51 |
messages.append({"role": "user", "content": message})
|
| 52 |
|
| 53 |
response = ""
|
|
@@ -62,21 +66,22 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
|
|
| 62 |
token = msg.choices[0].delta.get('content', None)
|
| 63 |
if token:
|
| 64 |
response += token
|
| 65 |
-
|
|
|
|
|
|
|
| 66 |
except Exception as e:
|
| 67 |
error_msg = f"μΆλ‘ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
| 68 |
-
|
|
|
|
| 69 |
|
| 70 |
css = """
|
| 71 |
footer {visibility: hidden}
|
| 72 |
"""
|
| 73 |
|
| 74 |
-
# ... (μ΄μ μ½λ λμΌ)
|
| 75 |
-
|
| 76 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
| 77 |
with gr.Row():
|
| 78 |
with gr.Column(scale=2):
|
| 79 |
-
chatbot = gr.Chatbot(height=600
|
| 80 |
msg = gr.Textbox(
|
| 81 |
label="λ©μμ§λ₯Ό μ
λ ₯νμΈμ",
|
| 82 |
show_label=False,
|
|
@@ -87,9 +92,9 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
|
| 87 |
|
| 88 |
with gr.Column(scale=1):
|
| 89 |
file_upload = gr.File(
|
| 90 |
-
label="νμΌ μ
λ‘λ (.
|
| 91 |
-
file_types=[".
|
| 92 |
-
type="filepath"
|
| 93 |
)
|
| 94 |
|
| 95 |
with gr.Accordion("κ³ κΈ μ€μ ", open=False):
|
|
|
|
| 22 |
except Exception as e:
|
| 23 |
return f"νμΌμ μ½λ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
| 24 |
|
| 25 |
+
def format_history(history):
|
| 26 |
+
formatted_history = []
|
| 27 |
+
for user_msg, assistant_msg in history:
|
| 28 |
+
formatted_history.append({"role": "user", "content": user_msg})
|
| 29 |
+
if assistant_msg:
|
| 30 |
+
formatted_history.append({"role": "assistant", "content": assistant_msg})
|
| 31 |
+
return formatted_history
|
| 32 |
+
|
| 33 |
def chat(message, history, uploaded_file, system_message="", max_tokens=4000, temperature=0.7, top_p=0.9):
|
| 34 |
system_prefix = """λ°λμ νκΈλ‘ λ΅λ³ν κ². λλ μ£Όμ΄μ§ μμ€μ½λλ λ°μ΄ν°λ₯Ό κΈ°λ°μΌλ‘ "μλΉμ€ μ¬μ© μ€λͺ
λ° μλ΄, Q&Aλ₯Ό νλ μν μ΄λ€". μμ£Ό μΉμ νκ³ μμΈνκ² 4000ν ν° μ΄μ Markdown νμμΌλ‘ μμ±νλΌ. λλ μ
λ ₯λ λ΄μ©μ κΈ°λ°μΌλ‘ μ¬μ© μ€λͺ
λ° μ§μ μλ΅μ μ§ννλ©°, μ΄μ©μμκ² λμμ μ£Όμ΄μΌ νλ€. μ΄μ©μκ° κΆκΈν΄ ν λ§ν λ΄μ©μ μΉμ νκ² μλ €μ£Όλλ‘ νλΌ. μ 체 λ΄μ©μ λν΄μλ 보μμ μ μ§νκ³ , ν€ κ° λ° μλν¬μΈνΈμ ꡬ체μ μΈ λͺ¨λΈμ 곡κ°νμ§ λ§λΌ."""
|
| 35 |
|
|
|
|
| 51 |
5. κΈ°λν¨κ³Ό λ° μ₯μ """
|
| 52 |
|
| 53 |
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
| 54 |
+
messages.extend(format_history(history))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
messages.append({"role": "user", "content": message})
|
| 56 |
|
| 57 |
response = ""
|
|
|
|
| 66 |
token = msg.choices[0].delta.get('content', None)
|
| 67 |
if token:
|
| 68 |
response += token
|
| 69 |
+
|
| 70 |
+
history = history + [[message, response]]
|
| 71 |
+
return "", history
|
| 72 |
except Exception as e:
|
| 73 |
error_msg = f"μΆλ‘ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
| 74 |
+
history = history + [[message, error_msg]]
|
| 75 |
+
return "", history
|
| 76 |
|
| 77 |
css = """
|
| 78 |
footer {visibility: hidden}
|
| 79 |
"""
|
| 80 |
|
|
|
|
|
|
|
| 81 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
| 82 |
with gr.Row():
|
| 83 |
with gr.Column(scale=2):
|
| 84 |
+
chatbot = gr.Chatbot(height=600) # type="messages" μ κ±°
|
| 85 |
msg = gr.Textbox(
|
| 86 |
label="λ©μμ§λ₯Ό μ
λ ₯νμΈμ",
|
| 87 |
show_label=False,
|
|
|
|
| 92 |
|
| 93 |
with gr.Column(scale=1):
|
| 94 |
file_upload = gr.File(
|
| 95 |
+
label="νμΌ μ
λ‘λ (.cod, .txt, .py, .parquet)",
|
| 96 |
+
file_types=[".cod", ".txt", ".py", ".parquet"],
|
| 97 |
+
type="filepath"
|
| 98 |
)
|
| 99 |
|
| 100 |
with gr.Accordion("κ³ κΈ μ€μ ", open=False):
|