Fix Chatbot: use type='messages' format to avoid gradio_client schema bug
Browse files
app.py
CHANGED
|
@@ -917,7 +917,8 @@ def create_app():
|
|
| 917 |
height=500,
|
| 918 |
show_label=True,
|
| 919 |
elem_id="chatbot",
|
| 920 |
-
bubble_full_width=False
|
|
|
|
| 921 |
)
|
| 922 |
|
| 923 |
# Needs selector (hidden until stage 5)
|
|
@@ -1039,7 +1040,10 @@ def create_app():
|
|
| 1039 |
|
| 1040 |
if stage == 5 and not sel_needs:
|
| 1041 |
bot_response = "Please take a moment to select your needs from the list above, then click 'Confirm My Needs' to continue."
|
| 1042 |
-
history = history + [
|
|
|
|
|
|
|
|
|
|
| 1043 |
return (
|
| 1044 |
history, "", stage, session, sel_needs,
|
| 1045 |
f"{stage}/13: {STAGE_NAMES[stage]}",
|
|
@@ -1056,7 +1060,10 @@ def create_app():
|
|
| 1056 |
)
|
| 1057 |
|
| 1058 |
if error:
|
| 1059 |
-
history = history + [
|
|
|
|
|
|
|
|
|
|
| 1060 |
return (
|
| 1061 |
history, "", stage, session, sel_needs,
|
| 1062 |
f"{stage}/13: {STAGE_NAMES[stage]}",
|
|
@@ -1065,9 +1072,12 @@ def create_app():
|
|
| 1065 |
)
|
| 1066 |
|
| 1067 |
if message != "continue":
|
| 1068 |
-
history = history + [
|
|
|
|
|
|
|
|
|
|
| 1069 |
else:
|
| 1070 |
-
history = history + [
|
| 1071 |
|
| 1072 |
show_needs = (next_stage == 5)
|
| 1073 |
|
|
@@ -1113,7 +1123,7 @@ def create_app():
|
|
| 1113 |
if not all_selected:
|
| 1114 |
return (
|
| 1115 |
all_selected,
|
| 1116 |
-
history + [
|
| 1117 |
stage,
|
| 1118 |
session
|
| 1119 |
)
|
|
@@ -1127,7 +1137,10 @@ def create_app():
|
|
| 1127 |
True
|
| 1128 |
)
|
| 1129 |
|
| 1130 |
-
history = history + [
|
|
|
|
|
|
|
|
|
|
| 1131 |
|
| 1132 |
return all_selected, history, next_stage, updated_session
|
| 1133 |
|
|
|
|
| 917 |
height=500,
|
| 918 |
show_label=True,
|
| 919 |
elem_id="chatbot",
|
| 920 |
+
bubble_full_width=False,
|
| 921 |
+
type="messages"
|
| 922 |
)
|
| 923 |
|
| 924 |
# Needs selector (hidden until stage 5)
|
|
|
|
| 1040 |
|
| 1041 |
if stage == 5 and not sel_needs:
|
| 1042 |
bot_response = "Please take a moment to select your needs from the list above, then click 'Confirm My Needs' to continue."
|
| 1043 |
+
history = history + [
|
| 1044 |
+
{"role": "user", "content": message},
|
| 1045 |
+
{"role": "assistant", "content": bot_response}
|
| 1046 |
+
]
|
| 1047 |
return (
|
| 1048 |
history, "", stage, session, sel_needs,
|
| 1049 |
f"{stage}/13: {STAGE_NAMES[stage]}",
|
|
|
|
| 1060 |
)
|
| 1061 |
|
| 1062 |
if error:
|
| 1063 |
+
history = history + [
|
| 1064 |
+
{"role": "user", "content": message},
|
| 1065 |
+
{"role": "assistant", "content": error}
|
| 1066 |
+
]
|
| 1067 |
return (
|
| 1068 |
history, "", stage, session, sel_needs,
|
| 1069 |
f"{stage}/13: {STAGE_NAMES[stage]}",
|
|
|
|
| 1072 |
)
|
| 1073 |
|
| 1074 |
if message != "continue":
|
| 1075 |
+
history = history + [
|
| 1076 |
+
{"role": "user", "content": message},
|
| 1077 |
+
{"role": "assistant", "content": response}
|
| 1078 |
+
]
|
| 1079 |
else:
|
| 1080 |
+
history = history + [{"role": "assistant", "content": response}]
|
| 1081 |
|
| 1082 |
show_needs = (next_stage == 5)
|
| 1083 |
|
|
|
|
| 1123 |
if not all_selected:
|
| 1124 |
return (
|
| 1125 |
all_selected,
|
| 1126 |
+
history + [{"role": "assistant", "content": "Please select at least one need before continuing."}],
|
| 1127 |
stage,
|
| 1128 |
session
|
| 1129 |
)
|
|
|
|
| 1137 |
True
|
| 1138 |
)
|
| 1139 |
|
| 1140 |
+
history = history + [
|
| 1141 |
+
{"role": "user", "content": f"Selected needs: {', '.join(all_selected)}"},
|
| 1142 |
+
{"role": "assistant", "content": response}
|
| 1143 |
+
]
|
| 1144 |
|
| 1145 |
return all_selected, history, next_stage, updated_session
|
| 1146 |
|