Update app.py
Browse files
app.py
CHANGED
@@ -148,6 +148,7 @@ def chat(message, history):
|
|
148 |
except Exception as e:
|
149 |
return f"Error: {e}"
|
150 |
|
|
|
151 |
def process_file(file):
|
152 |
file_path = file.name
|
153 |
file_extension = os.path.splitext(file_path)[1].lower()
|
@@ -175,13 +176,15 @@ def chat(message, history, file=None):
|
|
175 |
|
176 |
messages = [
|
177 |
{"role": "user", "parts": [system_prompt]},
|
178 |
-
*[{"role": "user", "parts": [msg[0]]} for msg in history],
|
179 |
{"role": "user", "parts": [combined_message]}
|
180 |
]
|
181 |
response = model.generate_content(messages)
|
182 |
-
|
|
|
|
|
183 |
except Exception as e:
|
184 |
-
return f"Error: {e}"
|
185 |
|
186 |
with gr.Blocks(title="🤖Chucho Bot - CopyXpert Sales Assistant") as demo:
|
187 |
gr.Markdown("# 🤖Chucho Bot - CopyXpert Sales Assistant")
|
|
|
148 |
except Exception as e:
|
149 |
return f"Error: {e}"
|
150 |
|
151 |
+
# Remove the first chat function as it's duplicated
|
152 |
def process_file(file):
|
153 |
file_path = file.name
|
154 |
file_extension = os.path.splitext(file_path)[1].lower()
|
|
|
176 |
|
177 |
messages = [
|
178 |
{"role": "user", "parts": [system_prompt]},
|
179 |
+
*[{"role": "user", "parts": [msg["content"]]} if isinstance(msg, dict) else {"role": "user", "parts": [msg[0]]} for msg in history],
|
180 |
{"role": "user", "parts": [combined_message]}
|
181 |
]
|
182 |
response = model.generate_content(messages)
|
183 |
+
|
184 |
+
# Return in the format expected by gr.Chatbot with type="messages"
|
185 |
+
return [{"role": "user", "content": combined_message}, {"role": "assistant", "content": response.text}]
|
186 |
except Exception as e:
|
187 |
+
return [{"role": "user", "content": combined_message}, {"role": "assistant", "content": f"Error: {e}"}]
|
188 |
|
189 |
with gr.Blocks(title="🤖Chucho Bot - CopyXpert Sales Assistant") as demo:
|
190 |
gr.Markdown("# 🤖Chucho Bot - CopyXpert Sales Assistant")
|