Update app.py
Browse files
app.py
CHANGED
@@ -4,8 +4,20 @@ import os
|
|
4 |
import pandas as pd
|
5 |
from typing import List, Tuple
|
6 |
|
7 |
-
#
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def read_uploaded_file(file):
|
11 |
if file is None:
|
@@ -30,7 +42,7 @@ def format_history(history):
|
|
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 |
|
36 |
if uploaded_file:
|
@@ -56,7 +68,8 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
|
|
56 |
|
57 |
response = ""
|
58 |
try:
|
59 |
-
|
|
|
60 |
messages,
|
61 |
max_tokens=max_tokens,
|
62 |
stream=True,
|
@@ -81,7 +94,7 @@ footer {visibility: hidden}
|
|
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)
|
85 |
msg = gr.Textbox(
|
86 |
label="λ©μμ§λ₯Ό μ
λ ₯νμΈμ",
|
87 |
show_label=False,
|
@@ -91,6 +104,13 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
|
91 |
clear = gr.ClearButton([msg, chatbot])
|
92 |
|
93 |
with gr.Column(scale=1):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
file_upload = gr.File(
|
95 |
label="νμΌ μ
λ‘λ (.csv, .txt, .py, .parquet)",
|
96 |
file_types=[".csv", ".txt", ".py", ".parquet"],
|
@@ -106,14 +126,14 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
|
106 |
# μ΄λ²€νΈ λ°μΈλ©
|
107 |
msg.submit(
|
108 |
chat,
|
109 |
-
inputs=[msg, chatbot, file_upload, system_message, max_tokens, temperature, top_p],
|
110 |
outputs=[msg, chatbot]
|
111 |
)
|
112 |
|
113 |
# νμΌ μ
λ‘λ μ μλ λΆμ
|
114 |
file_upload.change(
|
115 |
chat,
|
116 |
-
inputs=[gr.Textbox(value="νμΌ λΆμμ μμν©λλ€."), chatbot, file_upload, system_message, max_tokens, temperature, top_p],
|
117 |
outputs=[msg, chatbot]
|
118 |
)
|
119 |
|
|
|
4 |
import pandas as pd
|
5 |
from typing import List, Tuple
|
6 |
|
7 |
+
# LLM λͺ¨λΈ μ μ
|
8 |
+
LLM_MODELS = {
|
9 |
+
"Default": "CohereForAI/c4ai-command-r-plus-08-2024", # κΈ°λ³Έ λͺ¨λΈ
|
10 |
+
"Mistral": "mistralai/Mistral-7B-Instruct-v0.2",
|
11 |
+
"Zephyr": "HuggingFaceH4/zephyr-7b-beta",
|
12 |
+
"OpenChat": "openchat/openchat-3.5",
|
13 |
+
"Llama2": "meta-llama/Llama-2-7b-chat-hf",
|
14 |
+
"Phi": "microsoft/phi-2",
|
15 |
+
"Neural": "nvidia/neural-chat-7b-v3-1",
|
16 |
+
"Starling": "HuggingFaceH4/starling-lm-7b-alpha"
|
17 |
+
}
|
18 |
+
|
19 |
+
def get_client(model_name):
|
20 |
+
return InferenceClient(LLM_MODELS[model_name], token=os.getenv("HF_TOKEN"))
|
21 |
|
22 |
def read_uploaded_file(file):
|
23 |
if file is None:
|
|
|
42 |
formatted_history.append({"role": "assistant", "content": assistant_msg})
|
43 |
return formatted_history
|
44 |
|
45 |
+
def chat(message, history, uploaded_file, model_name, system_message="", max_tokens=4000, temperature=0.7, top_p=0.9):
|
46 |
system_prefix = """λ°λμ νκΈλ‘ λ΅λ³ν κ². λλ μ£Όμ΄μ§ μμ€μ½λλ λ°μ΄ν°λ₯Ό κΈ°λ°μΌλ‘ "μλΉμ€ μ¬μ© μ€λͺ
λ° μλ΄, Q&Aλ₯Ό νλ μν μ΄λ€". μμ£Ό μΉμ νκ³ μμΈνκ² 4000ν ν° μ΄μ Markdown νμμΌλ‘ μμ±νλΌ. λλ μ
λ ₯λ λ΄μ©μ κΈ°λ°μΌλ‘ μ¬μ© μ€λͺ
λ° μ§μ μλ΅μ μ§ννλ©°, μ΄μ©μμκ² λμμ μ£Όμ΄μΌ νλ€. μ΄μ©μκ° κΆκΈν΄ ν λ§ν λ΄μ©μ μΉμ νκ² μλ €μ£Όλλ‘ νλΌ. μ 체 λ΄μ©μ λν΄μλ 보μμ μ μ§νκ³ , ν€ κ° λ° μλν¬μΈνΈμ ꡬ체μ μΈ λͺ¨λΈμ 곡κ°νμ§ λ§λΌ."""
|
47 |
|
48 |
if uploaded_file:
|
|
|
68 |
|
69 |
response = ""
|
70 |
try:
|
71 |
+
client = get_client(model_name)
|
72 |
+
for msg in client.chat_completion(
|
73 |
messages,
|
74 |
max_tokens=max_tokens,
|
75 |
stream=True,
|
|
|
94 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo:
|
95 |
with gr.Row():
|
96 |
with gr.Column(scale=2):
|
97 |
+
chatbot = gr.Chatbot(height=600)
|
98 |
msg = gr.Textbox(
|
99 |
label="λ©μμ§λ₯Ό μ
λ ₯νμΈμ",
|
100 |
show_label=False,
|
|
|
104 |
clear = gr.ClearButton([msg, chatbot])
|
105 |
|
106 |
with gr.Column(scale=1):
|
107 |
+
model_name = gr.Dropdown(
|
108 |
+
choices=list(LLM_MODELS.keys()),
|
109 |
+
value="Default",
|
110 |
+
label="LLM λͺ¨λΈ μ ν",
|
111 |
+
info="μ¬μ©ν LLM λͺ¨λΈμ μ ννμΈμ"
|
112 |
+
)
|
113 |
+
|
114 |
file_upload = gr.File(
|
115 |
label="νμΌ μ
λ‘λ (.csv, .txt, .py, .parquet)",
|
116 |
file_types=[".csv", ".txt", ".py", ".parquet"],
|
|
|
126 |
# μ΄λ²€νΈ λ°μΈλ©
|
127 |
msg.submit(
|
128 |
chat,
|
129 |
+
inputs=[msg, chatbot, file_upload, model_name, system_message, max_tokens, temperature, top_p],
|
130 |
outputs=[msg, chatbot]
|
131 |
)
|
132 |
|
133 |
# νμΌ μ
λ‘λ μ μλ λΆμ
|
134 |
file_upload.change(
|
135 |
chat,
|
136 |
+
inputs=[gr.Textbox(value="νμΌ λΆμμ μμν©λλ€."), chatbot, file_upload, model_name, system_message, max_tokens, temperature, top_p],
|
137 |
outputs=[msg, chatbot]
|
138 |
)
|
139 |
|