Update app.py
Browse files
app.py
CHANGED
@@ -109,8 +109,72 @@ def chat(message, history, uploaded_file, system_message="", max_tokens=4000, te
|
|
109 |
νμ μμ λ°λ₯΄κ³ μΉμ νκ² μλ΅νλ©°, νμν κ²½μ° κ΅¬μ²΄μ μΈ μμλ μ€λͺ
μ μΆκ°νμ¬
|
110 |
μ΄ν΄λ₯Ό λκ² μ΅λλ€."""
|
111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
# UI ν
μ€νΈ νκΈν
|
113 |
-
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", title="
|
114 |
gr.HTML(
|
115 |
"""
|
116 |
<div style="text-align: center; max-width: 800px; margin: 0 auto;">
|
|
|
109 |
νμ μμ λ°λ₯΄κ³ μΉμ νκ² μλ΅νλ©°, νμν κ²½μ° κ΅¬μ²΄μ μΈ μμλ μ€λͺ
μ μΆκ°νμ¬
|
110 |
μ΄ν΄λ₯Ό λκ² μ΅λλ€."""
|
111 |
|
112 |
+
if uploaded_file:
|
113 |
+
content, file_type = read_uploaded_file(uploaded_file)
|
114 |
+
if file_type == "error":
|
115 |
+
return "", [{"role": "user", "content": message}, {"role": "assistant", "content": content}]
|
116 |
+
|
117 |
+
file_summary = analyze_file_content(content, file_type)
|
118 |
+
|
119 |
+
if file_type in ['parquet', 'csv']:
|
120 |
+
system_message += f"\n\nνμΌ λ΄μ©:\n```markdown\n{content}\n```"
|
121 |
+
else:
|
122 |
+
system_message += f"\n\nνμΌ λ΄μ©:\n```\n{content}\n```"
|
123 |
+
|
124 |
+
if message == "Starting file analysis...":
|
125 |
+
message = f"""[νμΌ κ΅¬μ‘° λΆμ] {file_summary}
|
126 |
+
|
127 |
+
λ€μ κ΄μ μμ λμμ λλ¦¬κ² μ΅λλ€:
|
128 |
+
1. π μ λ°μ μΈ λ΄μ© νμ
|
129 |
+
2. π‘ μ£Όμ νΉμ§ μ€λͺ
|
130 |
+
3. π― μ€μ©μ μΈ νμ© λ°©μ
|
131 |
+
4. β¨ κ°μ μ μ
|
132 |
+
5. π¬ μΆκ° μ§λ¬Έμ΄λ νμν μ€λͺ
"""
|
133 |
+
|
134 |
+
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
135 |
+
|
136 |
+
if history is not None:
|
137 |
+
for item in history:
|
138 |
+
if isinstance(item, dict):
|
139 |
+
messages.append(item)
|
140 |
+
elif isinstance(item, (list, tuple)) and len(item) == 2:
|
141 |
+
messages.append({"role": "user", "content": item[0]})
|
142 |
+
if item[1]:
|
143 |
+
messages.append({"role": "assistant", "content": item[1]})
|
144 |
+
|
145 |
+
messages.append({"role": "user", "content": message})
|
146 |
+
|
147 |
+
try:
|
148 |
+
client = get_client()
|
149 |
+
partial_message = ""
|
150 |
+
current_history = []
|
151 |
+
|
152 |
+
for msg in client.chat_completion(
|
153 |
+
messages,
|
154 |
+
max_tokens=max_tokens,
|
155 |
+
stream=True,
|
156 |
+
temperature=temperature,
|
157 |
+
top_p=top_p,
|
158 |
+
):
|
159 |
+
token = msg.choices[0].delta.get('content', None)
|
160 |
+
if token:
|
161 |
+
partial_message += token
|
162 |
+
current_history = [
|
163 |
+
{"role": "user", "content": message},
|
164 |
+
{"role": "assistant", "content": partial_message}
|
165 |
+
]
|
166 |
+
yield "", current_history
|
167 |
+
|
168 |
+
except Exception as e:
|
169 |
+
error_msg = f"β μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
170 |
+
error_history = [
|
171 |
+
{"role": "user", "content": message},
|
172 |
+
{"role": "assistant", "content": error_msg}
|
173 |
+
]
|
174 |
+
yield "", error_history
|
175 |
+
|
176 |
# UI ν
μ€νΈ νκΈν
|
177 |
+
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", title="GiniGEN π€") as demo:
|
178 |
gr.HTML(
|
179 |
"""
|
180 |
<div style="text-align: center; max-width: 800px; margin: 0 auto;">
|