akhaliq HF staff commited on
Commit
3e7d42c
1 Parent(s): 9a26341

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -80,20 +80,29 @@ def chatbot_response(api_key, user_inputs, history):
80
  user_text = user_inputs.get("text")
81
  user_image = user_inputs.get("image")
82
 
 
 
 
 
 
 
 
83
  # Append the user's message to the history
84
- if user_text or user_image:
85
- history.append(("User", user_text, user_image))
86
 
87
  # Get the API response
88
  api_result = get_api_response(api_key, user_inputs)
89
 
90
  if "error" in api_result:
91
  ai_message = f"Error: {api_result['error']}"
 
92
  else:
93
  ai_message = api_result["response"]
 
94
 
95
  # Append the AI's response to the history
96
- history.append(("AI", ai_message, None))
97
 
98
  return history, history
99
 
@@ -145,4 +154,4 @@ with gr.Blocks() as demo:
145
 
146
  # Launch the Gradio app
147
  if __name__ == "__main__":
148
- demo.launch()
 
80
  user_text = user_inputs.get("text")
81
  user_image = user_inputs.get("image")
82
 
83
+ # Prepare user content
84
+ user_content = []
85
+ if user_text:
86
+ user_content.append(user_text)
87
+ if user_image:
88
+ user_content.append(user_image)
89
+
90
  # Append the user's message to the history
91
+ if user_content:
92
+ history.append((user_content, None))
93
 
94
  # Get the API response
95
  api_result = get_api_response(api_key, user_inputs)
96
 
97
  if "error" in api_result:
98
  ai_message = f"Error: {api_result['error']}"
99
+ bot_content = [ai_message]
100
  else:
101
  ai_message = api_result["response"]
102
+ bot_content = [ai_message]
103
 
104
  # Append the AI's response to the history
105
+ history[-1] = (history[-1][0], bot_content)
106
 
107
  return history, history
108
 
 
154
 
155
  # Launch the Gradio app
156
  if __name__ == "__main__":
157
+ demo.launch()