Daemontatox commited on
Commit
44904f8
·
verified ·
1 Parent(s): 1bf9a9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +95 -91
app.py CHANGED
@@ -15,78 +15,62 @@ chat_api_key2 = os.environ.get("OPENROUTER_TOKEN")
15
  global_image_data_url = None
16
  global_image_prompt = None # Still stored if needed elsewhere
17
 
18
- def generate_prompt_from_options(difficulty, age, level, extra_details=""):
19
  """
20
  Uses the OpenAI chat model (via Hugging Face Inference API) to generate an image generation prompt
21
- based on the selected difficulty, age, autism level, and any extra details the user provides.
22
  """
23
  query = (
24
  f"""
25
- Follow the instructions below to Generate an image generation prompt for an educational image intended for Autistic children.
26
- Consider the following parameters:\n
27
- - Difficulty: {difficulty}\n
28
- - Age: {age}\n
29
- - Autism Level: {level}\n
30
- - Extra Details: {extra_details}\n\n
31
- Use the following system prompt to guide the image generation process:\n
32
 
33
- System Prompt:
34
 
35
- You are an image generation engine specializing in creating clear, calming, and visually supportive images designed for children with autism spectrum disorder (ASD). Your primary goal is to produce images that aid in understanding, communication, emotional regulation, and daily routines. Prioritize the following characteristics:
36
 
37
  **1. Clarity and Simplicity:**
38
-
39
- # * **Minimalist Backgrounds:** Use solid, muted colors (e.g., soft blues, greens, light grays, pastels) or very simple, uncluttered backgrounds. Avoid busy patterns, highly contrasting colors, or distracting elements.
40
- * **Clear Subject Focus:** The main subject of the image should be prominent and easily identifiable. Avoid unnecessary details that could cause confusion or sensory overload.
41
- * **Unambiguous Representations:** Objects and people should be depicted in a realistic and straightforward manner. Avoid abstract art or overly stylized representations. If depicting emotions, make them very clear and easily recognizable (e.g., a simple, wide smile for happiness, a single tear for sadness).
42
 
43
  **2. Visual Structure and Predictability:**
44
-
45
- * **Literal Interpretation:** The images should be highly literal. Avoid metaphors, symbolism, or implied meanings. If depicting a sequence of events, make each step visually distinct.
46
- * **Defined Borders:** Consider using clear outlines or borders around objects and people to enhance visual separation and definition.
47
- * **Consistent Style:** Maintain a consistent visual style across multiple images. This helps build familiarity and predictability.
48
 
49
  **3. Sensory Considerations:**
50
-
51
- * **Soft Color Palette:** Favor muted, calming colors. Avoid overly bright, saturated, or fluorescent colors.
52
- * **Reduced Visual Complexity:** Limit the number of elements in the image to prevent sensory overload.
53
- * **Smooth Textures:** If textures are depicted, they should appear smooth and non-threatening. Avoid rough, jagged, or overly detailed textures.
54
 
55
  **4. Positive and Supportive Imagery:**
56
-
57
- * **Positive Reinforcement:** Images should be encouraging and positive. Depict success, cooperation, and positive social interactions.
58
- * **Calm and Relaxing Scenes:** Consider scenes that promote calmness, such as nature scenes (e.g., a quiet forest, a calm beach), or familiar, safe environments (e.g., a cozy bedroom, a well-organized classroom).
59
- * **Avoidance of Triggers:** Be mindful of potential triggers for anxiety or distress. Avoid images that depict conflict, overwhelming crowds, or potentially frightening situations.
60
 
61
  **5. Specific Use Cases (Adapt as needed):**
62
-
63
- * **Social Stories:** If generating images for a social story, ensure each image clearly illustrates a single step in the sequence. Use consistent characters and settings throughout the story.
64
- * **Visual Schedules:** If creating images for a visual schedule, make each activity easily identifiable and visually distinct.
65
- * **Emotion Recognition:** If depicting emotions, use clear facial expressions and body language. Consider using a consistent character to represent different emotions.
66
- * **Communication Aids:** If creating images for communication, ensure the objects or actions are clearly depicted and easily recognizable.
67
- * **Daily Routines**: Brushing teeth, eating food, going to school.
68
- * **Learning concepts**: Shapes, colors, animals, numbers, alphabet.
69
 
70
  **Prompting Instructions:**
71
-
72
  When providing a prompt to the model, be as specific as possible, including:
73
-
74
- * **The subject of the image:** "A boy brushing his teeth."
75
- * **The desired style:** "Simple, clear, with a solid light blue background."
76
- * **The intended use:** "For a visual schedule."
77
- * **Any specific details:** "The boy should be smiling. The toothbrush should be blue."
78
- * **Emotions:** Clearly state the emotion "happy" or "calm."
79
-
80
- **Example Prompts (using the above system prompt as a base):**
81
-
82
- * "Generate an image for a visual schedule. The subject is 'eating lunch.' Show a child sitting at a table with a plate of food (sandwich, apple slices, and a glass of milk). The background should be a solid, pale green. The child should be smiling. Use a clear, simple style with defined outlines."
83
- * "Generate an image to help with emotion recognition. The subject is 'sad.' Show a child's face with a single tear rolling down their cheek and a downturned mouth. The background should be a solid, light gray. Use a simple, realistic style."
84
- * "Generate an image for a social story about going to the doctor. Show a child sitting in a doctor's waiting room, calmly looking at a book. The room should have a few simple toys and a window. The background should be a soft blue. The style should be clear and uncluttered."
85
- * "Generate a picture of two block shapes in a simple, cartoon style. One red square and one blue circle. Place them on a white background."
86
- * "Generate a cartoon image of a dog. Make the dog appear to be friendly and non-threatening. Use warm colors."
87
-
88
- Ensure your Prompts are acccurate and ensure the images are accurate and dont have any irregularities or deforamtions in them.
89
- use descriptive and detailed prompts
90
  """
91
  )
92
 
@@ -103,8 +87,8 @@ def generate_prompt_from_options(difficulty, age, level, extra_details=""):
103
  )
104
 
105
  stream = client.chat.completions.create(
106
- model="sophosympatheia/rogue-rose-103b-v0.2:free", # sophosympatheia/rogue-rose-103b-v0.2:free | google/gemini-2.0-flash-lite-preview-02-05:free
107
- temperature=0.5,
108
  messages=messages,
109
  max_tokens=8192,
110
  stream=True
@@ -115,7 +99,7 @@ def generate_prompt_from_options(difficulty, age, level, extra_details=""):
115
  response_text += chunk.choices[0].delta.content
116
  return response_text.strip()
117
 
118
- def generate_image_fn(selected_prompt, guidance_scale=7.5, negative_prompt="ugly, blurry, poorly drawn hands , Lewd , nude", num_inference_steps=50):
119
  """
120
  Uses the Hugging Face Inference API to generate an image from the provided prompt.
121
  Converts the image to a data URL for later use and stores the prompt globally.
@@ -146,43 +130,64 @@ def generate_image_fn(selected_prompt, guidance_scale=7.5, negative_prompt="ugly
146
 
147
  return image
148
 
149
- def generate_image_and_reset_chat(difficulty, age, level, extra_details, active_session, saved_sessions):
150
  """
151
- Saves any current active session into the saved sessions list. Then, using the three selected options and extra details,
152
  generates an image generation prompt, creates an image, and starts a new active session.
153
  """
154
  new_sessions = saved_sessions.copy()
155
  if active_session.get("prompt"):
156
  new_sessions.append(active_session)
157
 
158
- generated_prompt = generate_prompt_from_options(difficulty, age, level, extra_details)
159
  image = generate_image_fn(generated_prompt)
160
 
161
- new_active_session = {"prompt": generated_prompt, "image": global_image_data_url, "chat": []}
 
 
 
 
 
162
  return image, new_active_session, new_sessions
163
 
164
- def compare_details_chat_fn(user_details, additional_criteria):
165
  """
166
  Uses the vision language model to evaluate the user description based solely on the generated image.
167
  The message includes both the image (using its data URL) and the user’s text.
168
- Now also appends any additional criteria provided by the user.
169
  """
170
  if not global_image_data_url:
171
  return "Please generate an image first."
172
 
173
- additional_text = ""
174
- if additional_criteria and additional_criteria.strip():
175
- additional_text = f"\n\nAdditional Evaluation Criteria: {additional_criteria.strip()}"
176
 
177
  message_text = (
178
  f"Based on the image provided above, please evaluate the following description given by the child:\n"
179
- f"'{user_details}'"
180
- f"{additional_text}\n\n"
181
- "You are a friendly and encouraging teacher, guiding a child in describing an image. Speak directly to the child using simple, clear language. Provide positive reinforcement when the child gives a correct or accurate description.\n\n"
182
- "If the child's description is incorrect or inaccurate, gently guide them with hints rather than direct corrections. Use Hint before providing guidance. Keep your hints playful and engaging to encourage curiosity.\n\n"
183
- "Avoid repeating the child’s description. Instead, focus on giving feedback based on the image. If the description is correct, acknowledge it warmly with praise.\n\n"
184
- "Keep the conversation going by asking open-ended questions about the image to encourage the child to observe and think more deeply. Use questions that spark curiosity, such as 'What else do you see?' or 'Why do you think that is happening?'\n\n"
185
- "Do not mention your own thoughts, system prompts, or provide direct details about the image. Stay fully engaged in a natural, conversational way, making learning fun and interactive!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  )
187
 
188
  messages = [
@@ -218,21 +223,22 @@ def compare_details_chat_fn(user_details, additional_criteria):
218
  response_text += chunk.choices[0].delta.content
219
  return response_text
220
 
221
- def chat_respond(user_message, additional_criteria, active_session, saved_sessions):
222
  """
223
  Processes a new chat message. If no image has been generated yet, instructs the user to generate one.
224
- Otherwise, sends the generated image, the user’s description, and any additional criteria to the vision language model for evaluation,
225
  then appends the conversation to the active session's chat history.
226
  """
227
  if not active_session.get("image"):
228
  bot_message = "Please generate an image first."
229
  else:
230
- bot_message = compare_details_chat_fn(user_message, additional_criteria)
 
231
 
232
  updated_chat = active_session.get("chat", []) + [(user_message, bot_message)]
233
  active_session["chat"] = updated_chat
234
- # Clear only the chat message after processing, keeping the additional criteria intact.
235
- return "", additional_criteria, updated_chat, saved_sessions, active_session
236
 
237
  def update_sessions(saved_sessions, active_session):
238
  """
@@ -253,7 +259,7 @@ level_options = ["Level 1", "Level 2", "Level 3"]
253
  # Create the Gradio Interface (Single-Page) with a Sidebar for Session Details
254
  ##############################################
255
  with gr.Blocks() as demo:
256
- active_session = gr.State({"prompt": None, "image": None, "chat": []})
257
  saved_sessions = gr.State([])
258
 
259
  with gr.Column():
@@ -265,18 +271,18 @@ with gr.Blocks() as demo:
265
  gr.Markdown("Select options to create a custom prompt for image generation:")
266
  with gr.Row():
267
  difficulty_dropdown = gr.Dropdown(label="Difficulty", choices=difficulty_options, value=difficulty_options[0])
268
- age_input = gr.Textbox(label="Age", placeholder="Enter your age...", value="3")
269
  level_dropdown = gr.Dropdown(label="Level", choices=level_options, value=level_options[0])
270
- extra_details_input = gr.Textbox(
271
- label="Extra Details (optional)",
272
- placeholder="Enter any additional details for the image...",
273
  lines=2
274
  )
275
  generate_btn = gr.Button("Generate Image")
276
  img_output = gr.Image(label="Generated Image")
277
  generate_btn.click(
278
  generate_image_and_reset_chat,
279
- inputs=[difficulty_dropdown, age_input, level_dropdown, extra_details_input, active_session, saved_sessions],
280
  outputs=[img_output, active_session, saved_sessions]
281
  )
282
 
@@ -285,25 +291,23 @@ with gr.Blocks() as demo:
285
  gr.Markdown("## Chat about the Image")
286
  gr.Markdown(
287
  "After generating an image, type details or descriptions about it. "
288
- "Your message will be sent along with the image to a vision language model, "
289
- "which will evaluate your description based on what it sees in the image. "
290
- "You can also provide additional criteria for evaluation."
291
  )
292
  chatbot = gr.Chatbot(label="Chat History")
293
  with gr.Row():
294
  chat_input = gr.Textbox(label="Your Message", placeholder="Type your description here...", show_label=False)
295
- additional_criteria_input = gr.Textbox(label="Additional Evaluation Criteria", placeholder="Enter extra criteria for evaluation...", lines=2)
296
  send_btn = gr.Button("Send")
297
 
298
  send_btn.click(
299
  chat_respond,
300
- inputs=[chat_input, additional_criteria_input, active_session, saved_sessions],
301
- outputs=[chat_input, additional_criteria_input, chatbot, saved_sessions, active_session]
302
  )
303
  chat_input.submit(
304
  chat_respond,
305
- inputs=[chat_input, additional_criteria_input, active_session, saved_sessions],
306
- outputs=[chat_input, additional_criteria_input, chatbot, saved_sessions, active_session]
307
  )
308
 
309
  # ----- Sidebar Section for Session Details -----
@@ -312,7 +316,7 @@ with gr.Blocks() as demo:
312
  gr.Markdown(
313
  "This sidebar automatically saves finished chat sessions. "
314
  "Each session includes the prompt used, the generated image (as a data URL), "
315
- "and the chat history (user messages and corresponding bot responses)."
316
  )
317
  sessions_output = gr.JSON(label="Session Details", value={})
318
  active_session.change(update_sessions, inputs=[saved_sessions, active_session], outputs=sessions_output)
 
15
  global_image_data_url = None
16
  global_image_prompt = None # Still stored if needed elsewhere
17
 
18
+ def generate_prompt_from_options(difficulty, age, level, treatment_plan=""):
19
  """
20
  Uses the OpenAI chat model (via Hugging Face Inference API) to generate an image generation prompt
21
+ based on the selected difficulty, age, autism level, and the treatment plan the user provides.
22
  """
23
  query = (
24
  f"""
25
+ Follow the instructions below to generate an image generation prompt for an educational image intended for autistic children.
26
+ Consider the following parameters:
27
+ - Difficulty: {difficulty}
28
+ - Age: {age}
29
+ - Autism Level: {level}
30
+ - Treatment Plan: {treatment_plan}
 
31
 
32
+ Use the following system prompt to guide the image generation process:
33
 
34
+ You are an image generation engine specializing in creating clear, calming, and visually supportive images designed for children with autism spectrum disorder (ASD). Your primary goal is to produce images that aid in understanding, communication, emotional regulation, and daily routines. Prioritize the following characteristics:
35
 
36
  **1. Clarity and Simplicity:**
37
+ - **Minimalist Backgrounds:** Use solid, muted colors (e.g., soft blues, greens, light grays, pastels) or very simple, uncluttered backgrounds. Avoid busy patterns, highly contrasting colors, or distracting elements.
38
+ - **Clear Subject Focus:** The main subject of the image should be prominent and easily identifiable. Avoid unnecessary details that could cause confusion or sensory overload.
39
+ - **Unambiguous Representations:** Objects and people should be depicted in a realistic and straightforward manner. Avoid abstract art or overly stylized representations. If depicting emotions, make them very clear and easily recognizable.
 
40
 
41
  **2. Visual Structure and Predictability:**
42
+ - **Literal Interpretation:** The images should be highly literal. Avoid metaphors, symbolism, or implied meanings. If depicting a sequence of events, make each step visually distinct.
43
+ - **Defined Borders:** Consider using clear outlines or borders around objects and people to enhance visual separation and definition.
44
+ - **Consistent Style:** Maintain a consistent visual style across multiple images. This helps build familiarity and predictability.
 
45
 
46
  **3. Sensory Considerations:**
47
+ - **Soft Color Palette:** Favor muted, calming colors. Avoid overly bright, saturated, or fluorescent colors.
48
+ - **Reduced Visual Complexity:** Limit the number of elements in the image to prevent sensory overload.
49
+ - **Smooth Textures:** If textures are depicted, they should appear smooth and non-threatening. Avoid rough, jagged, or overly detailed textures.
 
50
 
51
  **4. Positive and Supportive Imagery:**
52
+ - **Positive Reinforcement:** Images should be encouraging and positive. Depict success, cooperation, and positive social interactions.
53
+ - **Calm and Relaxing Scenes:** Consider scenes that promote calmness, such as nature scenes (e.g., a quiet forest, a calm beach) or familiar, safe environments (e.g., a cozy bedroom, a well-organized classroom).
54
+ - **Avoidance of Triggers:** Be mindful of potential triggers for anxiety or distress. Avoid images that depict conflict, overwhelming crowds, or potentially frightening situations.
 
55
 
56
  **5. Specific Use Cases (Adapt as needed):**
57
+ - **Social Stories:** If generating images for a social story, ensure each image clearly illustrates a single step in the sequence. Use consistent characters and settings throughout the story.
58
+ - **Visual Schedules:** If creating images for a visual schedule, make each activity easily identifiable and visually distinct.
59
+ - **Emotion Recognition:** If depicting emotions, use clear facial expressions and body language. Consider using a consistent character to represent different emotions.
60
+ - **Communication Aids:** If creating images for communication, ensure the objects or actions are clearly depicted and easily recognizable.
61
+ - **Daily Routines:** e.g., brushing teeth, eating food, going to school.
62
+ - **Learning Concepts:** e.g., shapes, colors, animals, numbers, alphabet.
 
63
 
64
  **Prompting Instructions:**
 
65
  When providing a prompt to the model, be as specific as possible, including:
66
+ - **The subject of the image:** e.g., "A boy brushing his teeth."
67
+ - **The desired style:** e.g., "Simple, clear, with a solid light blue background."
68
+ - **The intended use:** e.g., "For a visual schedule."
69
+ - **Any specific details:** e.g., "The boy should be smiling. The toothbrush should be blue."
70
+ - **Emotions:** Clearly state the emotion ("happy" or "calm").
71
+
72
+ Ensure your prompt is accurate and the generated images are clear without irregularities or deformations.
73
+ Use descriptive and detailed language.
 
 
 
 
 
 
 
 
 
74
  """
75
  )
76
 
 
87
  )
88
 
89
  stream = client.chat.completions.create(
90
+ model="google/gemini-2.0-pro-exp-02-05:free", # google/gemini-2.0-pro-exp-02-05:free # sophosympatheia/rogue-rose-103b-v0.2:free
91
+ temperature=0.9,
92
  messages=messages,
93
  max_tokens=8192,
94
  stream=True
 
99
  response_text += chunk.choices[0].delta.content
100
  return response_text.strip()
101
 
102
+ def generate_image_fn(selected_prompt, guidance_scale=7.5, negative_prompt="ugly, blurry, poorly drawn hands, lewd, nude , deformed , missing limbs, missing eyes, missing arms, missing legs, missing nose, missing mouth, missing ears, missing teeth", num_inference_steps=50):
103
  """
104
  Uses the Hugging Face Inference API to generate an image from the provided prompt.
105
  Converts the image to a data URL for later use and stores the prompt globally.
 
130
 
131
  return image
132
 
133
+ def generate_image_and_reset_chat(difficulty, age, level, treatment_plan, active_session, saved_sessions):
134
  """
135
+ Saves any current active session into the saved sessions list. Then, using the selected options and treatment plan,
136
  generates an image generation prompt, creates an image, and starts a new active session.
137
  """
138
  new_sessions = saved_sessions.copy()
139
  if active_session.get("prompt"):
140
  new_sessions.append(active_session)
141
 
142
+ generated_prompt = generate_prompt_from_options(difficulty, age, level, treatment_plan)
143
  image = generate_image_fn(generated_prompt)
144
 
145
+ new_active_session = {
146
+ "prompt": generated_prompt,
147
+ "image": global_image_data_url,
148
+ "chat": [],
149
+ "treatment_plan": treatment_plan
150
+ }
151
  return image, new_active_session, new_sessions
152
 
153
+ def compare_details_chat_fn(user_details, treatment_plan):
154
  """
155
  Uses the vision language model to evaluate the user description based solely on the generated image.
156
  The message includes both the image (using its data URL) and the user’s text.
157
+ The provided treatment plan is included so the model keeps it in mind during evaluation.
158
  """
159
  if not global_image_data_url:
160
  return "Please generate an image first."
161
 
162
+ treatment_text = ""
163
+ if treatment_plan and treatment_plan.strip():
164
+ treatment_text = f"\n\nTreatment Plan: {treatment_plan.strip()}"
165
 
166
  message_text = (
167
  f"Based on the image provided above, please evaluate the following description given by the child:\n"
168
+ f"'{user_details}'\n\n"
169
+ "You are a friendly and encouraging teacher, guiding a child in describing an image. "
170
+ "Speak directly to the child using simple, clear language. Provide positive reinforcement when the child gives a correct or accurate description.\n\n"
171
+ "If the child's description is incorrect or inaccurate, gently guide them with hints rather than direct corrections. "
172
+ "Prefix your hints with 'Hint:' and keep them playful and engaging to encourage curiosity.\n\n"
173
+ "Focus your feedback on the following evaluation criteria:\n"
174
+ "1. **Object Identification** Does the child correctly name objects in the image?\n"
175
+ "2. **Color & Shape Accuracy** – Are colors, shapes, and basic attributes described correctly?\n"
176
+ "3. **Detail Perception** – Does the child notice small details, textures, and patterns?\n"
177
+ "4. **Spatial Awareness** – Are object positions and relationships described correctly?\n"
178
+ "5. **Action & Interaction Recognition** – Does the child describe interactions between objects or characters?\n"
179
+ "6. **Emotional & Contextual Understanding** – Can they recognize emotions, intent, or context in the image?\n"
180
+ "7. **Coherence & Clarity** – Is their response structured, logical, and understandable?\n"
181
+ "8. **Creativity & Interpretation** – Do they provide unique observations or imaginative descriptions?\n"
182
+ "9. **Comparison to Expected Response** – How does their description compare to an ideal response?"
183
+ f"{treatment_text}\n\n"
184
+ "### Response Format:\n"
185
+ "- [Assign a score based on accuracy, detail, and clarity]\n"
186
+ "- [Highlight what the child described well]\n"
187
+ "- [Mention key details they missed or misinterpreted]\n"
188
+ "- [Provide a playful hint to guide them toward the correct observation]\n"
189
+ "- [Ask an open-ended question to keep them engaged]\n\n"
190
+ "Do not mention system prompts or provide direct details about the image. Stay fully engaged in a natural, conversational way to make learning fun and interactive!"
191
  )
192
 
193
  messages = [
 
223
  response_text += chunk.choices[0].delta.content
224
  return response_text
225
 
226
+ def chat_respond(user_message, active_session, saved_sessions):
227
  """
228
  Processes a new chat message. If no image has been generated yet, instructs the user to generate one.
229
+ Otherwise, sends the generated image, the user’s description, and the stored treatment plan to the vision language model for evaluation,
230
  then appends the conversation to the active session's chat history.
231
  """
232
  if not active_session.get("image"):
233
  bot_message = "Please generate an image first."
234
  else:
235
+ treatment_plan = active_session.get("treatment_plan", "")
236
+ bot_message = compare_details_chat_fn(user_message, treatment_plan)
237
 
238
  updated_chat = active_session.get("chat", []) + [(user_message, bot_message)]
239
  active_session["chat"] = updated_chat
240
+ # Clear only the chat message after processing.
241
+ return "", updated_chat, saved_sessions, active_session
242
 
243
  def update_sessions(saved_sessions, active_session):
244
  """
 
259
  # Create the Gradio Interface (Single-Page) with a Sidebar for Session Details
260
  ##############################################
261
  with gr.Blocks() as demo:
262
+ active_session = gr.State({"prompt": None, "image": None, "chat": [], "treatment_plan": ""})
263
  saved_sessions = gr.State([])
264
 
265
  with gr.Column():
 
271
  gr.Markdown("Select options to create a custom prompt for image generation:")
272
  with gr.Row():
273
  difficulty_dropdown = gr.Dropdown(label="Difficulty", choices=difficulty_options, value=difficulty_options[0])
274
+ age_input = gr.Textbox(label="Age", placeholder="Enter age...", value="5")
275
  level_dropdown = gr.Dropdown(label="Level", choices=level_options, value=level_options[0])
276
+ treatment_plan_input = gr.Textbox(
277
+ label="Treatment Plan",
278
+ placeholder="Enter the treatment plan to guide the image generation...",
279
  lines=2
280
  )
281
  generate_btn = gr.Button("Generate Image")
282
  img_output = gr.Image(label="Generated Image")
283
  generate_btn.click(
284
  generate_image_and_reset_chat,
285
+ inputs=[difficulty_dropdown, age_input, level_dropdown, treatment_plan_input, active_session, saved_sessions],
286
  outputs=[img_output, active_session, saved_sessions]
287
  )
288
 
 
291
  gr.Markdown("## Chat about the Image")
292
  gr.Markdown(
293
  "After generating an image, type details or descriptions about it. "
294
+ "Your message, along with the generated image and the stored treatment plan, "
295
+ "will be sent to a vision language model for evaluation."
 
296
  )
297
  chatbot = gr.Chatbot(label="Chat History")
298
  with gr.Row():
299
  chat_input = gr.Textbox(label="Your Message", placeholder="Type your description here...", show_label=False)
 
300
  send_btn = gr.Button("Send")
301
 
302
  send_btn.click(
303
  chat_respond,
304
+ inputs=[chat_input, active_session, saved_sessions],
305
+ outputs=[chat_input, chatbot, saved_sessions, active_session]
306
  )
307
  chat_input.submit(
308
  chat_respond,
309
+ inputs=[chat_input, active_session, saved_sessions],
310
+ outputs=[chat_input, chatbot, saved_sessions, active_session]
311
  )
312
 
313
  # ----- Sidebar Section for Session Details -----
 
316
  gr.Markdown(
317
  "This sidebar automatically saves finished chat sessions. "
318
  "Each session includes the prompt used, the generated image (as a data URL), "
319
+ "the treatment plan, and the chat history (user messages and corresponding bot responses)."
320
  )
321
  sessions_output = gr.JSON(label="Session Details", value={})
322
  active_session.change(update_sessions, inputs=[saved_sessions, active_session], outputs=sessions_output)