Update app.py
Browse files
app.py
CHANGED
@@ -109,8 +109,7 @@ Provide detailed and structured analysis from an expert perspective, but explain
|
|
109 |
if uploaded_file:
|
110 |
content, file_type = read_uploaded_file(uploaded_file)
|
111 |
if file_type == "error":
|
112 |
-
|
113 |
-
return
|
114 |
|
115 |
file_summary = analyze_file_content(content, file_type)
|
116 |
|
@@ -131,7 +130,13 @@ Please provide detailed analysis from these perspectives:
|
|
131 |
6. 🎯 Practical applications and recommendations"""
|
132 |
|
133 |
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
messages.append({"role": "user", "content": message})
|
136 |
|
137 |
try:
|
@@ -148,11 +153,18 @@ Please provide detailed analysis from these perspectives:
|
|
148 |
token = msg.choices[0].delta.get('content', None)
|
149 |
if token:
|
150 |
partial_message += token
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
except Exception as e:
|
154 |
error_msg = f"❌ Inference error: {str(e)}"
|
155 |
-
|
|
|
156 |
|
157 |
css = """
|
158 |
footer {visibility: hidden}
|
|
|
109 |
if uploaded_file:
|
110 |
content, file_type = read_uploaded_file(uploaded_file)
|
111 |
if file_type == "error":
|
112 |
+
return "", [{"role": "user", "content": message}, {"role": "assistant", "content": content}]
|
|
|
113 |
|
114 |
file_summary = analyze_file_content(content, file_type)
|
115 |
|
|
|
130 |
6. 🎯 Practical applications and recommendations"""
|
131 |
|
132 |
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
133 |
+
|
134 |
+
# Convert history to message format
|
135 |
+
for h in history:
|
136 |
+
messages.append({"role": "user", "content": h[0]})
|
137 |
+
if h[1]:
|
138 |
+
messages.append({"role": "assistant", "content": h[1]})
|
139 |
+
|
140 |
messages.append({"role": "user", "content": message})
|
141 |
|
142 |
try:
|
|
|
153 |
token = msg.choices[0].delta.get('content', None)
|
154 |
if token:
|
155 |
partial_message += token
|
156 |
+
new_history = history + [[message, partial_message]]
|
157 |
+
formatted_history = []
|
158 |
+
for h in new_history:
|
159 |
+
formatted_history.append({"role": "user", "content": h[0]})
|
160 |
+
if h[1]:
|
161 |
+
formatted_history.append({"role": "assistant", "content": h[1]})
|
162 |
+
yield "", formatted_history
|
163 |
|
164 |
except Exception as e:
|
165 |
error_msg = f"❌ Inference error: {str(e)}"
|
166 |
+
formatted_history = history + [[message, error_msg]]
|
167 |
+
yield "", [{"role": "user", "content": h[0], "role": "assistant", "content": h[1]} for h in formatted_history]
|
168 |
|
169 |
css = """
|
170 |
footer {visibility: hidden}
|