Spaces:
Paused
Paused
Update app/app.py
Browse files- app/app.py +17 -7
app/app.py
CHANGED
|
@@ -124,8 +124,13 @@ def generate_response(
|
|
| 124 |
try:
|
| 125 |
start_time = time.time()
|
| 126 |
|
| 127 |
-
#
|
| 128 |
-
conv_history =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
# Update pipeline history
|
| 131 |
pipeline.conversation_history = conv_history
|
|
@@ -147,9 +152,8 @@ def generate_response(
|
|
| 147 |
|
| 148 |
status_info = " | ".join(status_parts)
|
| 149 |
|
| 150 |
-
# Update history (
|
| 151 |
-
history.append(
|
| 152 |
-
history.append({"role": "assistant", "content": result.final_response})
|
| 153 |
|
| 154 |
return result.final_response, history, status_info
|
| 155 |
|
|
@@ -171,9 +175,16 @@ def export_conversation(history: list) -> str:
|
|
| 171 |
if not history:
|
| 172 |
return None
|
| 173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
export_data = {
|
| 175 |
"exported_at": datetime.now().isoformat(),
|
| 176 |
-
"messages":
|
| 177 |
}
|
| 178 |
|
| 179 |
# Create temp file
|
|
@@ -223,7 +234,6 @@ def create_app(
|
|
| 223 |
label="Conversation",
|
| 224 |
height=500,
|
| 225 |
elem_classes=["chat-container"],
|
| 226 |
-
type="messages",
|
| 227 |
)
|
| 228 |
|
| 229 |
# Input area
|
|
|
|
| 124 |
try:
|
| 125 |
start_time = time.time()
|
| 126 |
|
| 127 |
+
# Convert tuple history to messages format for pipeline
|
| 128 |
+
conv_history = []
|
| 129 |
+
if history:
|
| 130 |
+
for user_msg, bot_msg in history:
|
| 131 |
+
conv_history.append({"role": "user", "content": user_msg})
|
| 132 |
+
if bot_msg:
|
| 133 |
+
conv_history.append({"role": "assistant", "content": bot_msg})
|
| 134 |
|
| 135 |
# Update pipeline history
|
| 136 |
pipeline.conversation_history = conv_history
|
|
|
|
| 152 |
|
| 153 |
status_info = " | ".join(status_parts)
|
| 154 |
|
| 155 |
+
# Update history (tuple format for Gradio)
|
| 156 |
+
history.append((message, result.final_response))
|
|
|
|
| 157 |
|
| 158 |
return result.final_response, history, status_info
|
| 159 |
|
|
|
|
| 175 |
if not history:
|
| 176 |
return None
|
| 177 |
|
| 178 |
+
# Convert tuple format to messages format for export
|
| 179 |
+
messages = []
|
| 180 |
+
for user_msg, bot_msg in history:
|
| 181 |
+
messages.append({"role": "user", "content": user_msg})
|
| 182 |
+
if bot_msg:
|
| 183 |
+
messages.append({"role": "assistant", "content": bot_msg})
|
| 184 |
+
|
| 185 |
export_data = {
|
| 186 |
"exported_at": datetime.now().isoformat(),
|
| 187 |
+
"messages": messages,
|
| 188 |
}
|
| 189 |
|
| 190 |
# Create temp file
|
|
|
|
| 234 |
label="Conversation",
|
| 235 |
height=500,
|
| 236 |
elem_classes=["chat-container"],
|
|
|
|
| 237 |
)
|
| 238 |
|
| 239 |
# Input area
|