jostlebot Claude Opus 4.5 commited on
Commit
e3f7330
·
1 Parent(s): 2953189

Fix Gradio 5.x compatibility: use messages format for Chatbot

Browse files

Change Chatbot type from 'tuples' to 'messages' and update all
history handling to use dict format with role/content keys.
This resolves the TypeError in gradio_client/utils.py.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -882,7 +882,7 @@ def create_app():
882
  show_label=True,
883
  elem_id="chatbot",
884
  bubble_full_width=False,
885
- type="tuples"
886
  )
887
 
888
  # Needs selector (hidden until stage 5)
@@ -1004,7 +1004,10 @@ def create_app():
1004
 
1005
  if stage == 5 and not sel_needs:
1006
  bot_response = "Please take a moment to select your needs from the list above, then click 'Confirm My Needs' to continue."
1007
- history = history + [[message, bot_response]]
 
 
 
1008
  return (
1009
  history, "", stage, session, sel_needs,
1010
  f"{stage}/13: {STAGE_NAMES[stage]}",
@@ -1021,7 +1024,10 @@ def create_app():
1021
  )
1022
 
1023
  if error:
1024
- history = history + [[message, error]]
 
 
 
1025
  return (
1026
  history, "", stage, session, sel_needs,
1027
  f"{stage}/13: {STAGE_NAMES[stage]}",
@@ -1030,9 +1036,14 @@ def create_app():
1030
  )
1031
 
1032
  if message != "continue":
1033
- history = history + [[message, response]]
 
 
 
1034
  else:
1035
- history = history + [[None, response]]
 
 
1036
 
1037
  show_needs = (next_stage == 5)
1038
 
@@ -1078,7 +1089,7 @@ def create_app():
1078
  if not all_selected:
1079
  return (
1080
  all_selected,
1081
- history + [[None, "Please select at least one need before continuing."]],
1082
  stage,
1083
  session
1084
  )
@@ -1092,7 +1103,10 @@ def create_app():
1092
  True
1093
  )
1094
 
1095
- history = history + [[f"Selected needs: {', '.join(all_selected)}", response]]
 
 
 
1096
 
1097
  return all_selected, history, next_stage, updated_session
1098
 
 
882
  show_label=True,
883
  elem_id="chatbot",
884
  bubble_full_width=False,
885
+ type="messages"
886
  )
887
 
888
  # Needs selector (hidden until stage 5)
 
1004
 
1005
  if stage == 5 and not sel_needs:
1006
  bot_response = "Please take a moment to select your needs from the list above, then click 'Confirm My Needs' to continue."
1007
+ history = history + [
1008
+ {"role": "user", "content": message},
1009
+ {"role": "assistant", "content": bot_response}
1010
+ ]
1011
  return (
1012
  history, "", stage, session, sel_needs,
1013
  f"{stage}/13: {STAGE_NAMES[stage]}",
 
1024
  )
1025
 
1026
  if error:
1027
+ history = history + [
1028
+ {"role": "user", "content": message},
1029
+ {"role": "assistant", "content": error}
1030
+ ]
1031
  return (
1032
  history, "", stage, session, sel_needs,
1033
  f"{stage}/13: {STAGE_NAMES[stage]}",
 
1036
  )
1037
 
1038
  if message != "continue":
1039
+ history = history + [
1040
+ {"role": "user", "content": message},
1041
+ {"role": "assistant", "content": response}
1042
+ ]
1043
  else:
1044
+ history = history + [
1045
+ {"role": "assistant", "content": response}
1046
+ ]
1047
 
1048
  show_needs = (next_stage == 5)
1049
 
 
1089
  if not all_selected:
1090
  return (
1091
  all_selected,
1092
+ history + [{"role": "assistant", "content": "Please select at least one need before continuing."}],
1093
  stage,
1094
  session
1095
  )
 
1103
  True
1104
  )
1105
 
1106
+ history = history + [
1107
+ {"role": "user", "content": f"Selected needs: {', '.join(all_selected)}"},
1108
+ {"role": "assistant", "content": response}
1109
+ ]
1110
 
1111
  return all_selected, history, next_stage, updated_session
1112