StevenMSAI commited on
Commit
ec284b1
·
verified ·
1 Parent(s): 7f620c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -190,21 +190,23 @@ def reply(message, history):
190
 
191
  # -------- UI --------
192
 
 
 
193
  initial_messages = []
194
-
195
- # Use a Gradio component for media so it renders inline (messages content can be components). :contentReference[oaicite:2]{index=2}
196
  if os.path.exists(WELCOME_IMAGE_PATH):
197
  initial_messages.append({
198
  "role": "assistant",
199
- "content": gr.Image(value=WELCOME_IMAGE_PATH) # inline image, not a file tile
 
 
 
200
  })
201
  else:
202
  print(f"[startup] Welcome image not found at {WELCOME_IMAGE_PATH}; showing text only.")
203
 
204
- # Text message can just be a plain string in messages format. :contentReference[oaicite:3]{index=3}
205
  initial_messages.append({
206
  "role": "assistant",
207
- "content": WELCOME_TEXT
208
  })
209
 
210
  chatbot_component = gr.Chatbot(
@@ -220,12 +222,12 @@ demo = gr.ChatInterface(
220
  type="messages",
221
  )
222
 
223
- # -------- Launch (SSR off + Spaces-friendly + expose assets) --------
224
  if __name__ == "__main__":
225
  demo.launch(
226
  ssr_mode=False,
227
  server_name="0.0.0.0",
228
  server_port=int(os.getenv("PORT", "7860")),
229
  share=False,
230
- allowed_paths=["assets"], # expose local assets for serving, e.g. cat.png
231
  )
 
190
 
191
  # -------- UI --------
192
 
193
+ # Build initial messages:
194
+ # Per Gradio's messages spec, `content` may be a string OR a *file dict* with at least `path`. :contentReference[oaicite:1]{index=1}
195
  initial_messages = []
 
 
196
  if os.path.exists(WELCOME_IMAGE_PATH):
197
  initial_messages.append({
198
  "role": "assistant",
199
+ "content": {
200
+ "path": WELCOME_IMAGE_PATH, # server filepath
201
+ "mime_type": "image/png" # helps render inline as an image
202
+ }
203
  })
204
  else:
205
  print(f"[startup] Welcome image not found at {WELCOME_IMAGE_PATH}; showing text only.")
206
 
 
207
  initial_messages.append({
208
  "role": "assistant",
209
+ "content": WELCOME_TEXT # plain text message
210
  })
211
 
212
  chatbot_component = gr.Chatbot(
 
222
  type="messages",
223
  )
224
 
225
+ # -------- Launch (SSR off + Spaces-friendly) --------
226
  if __name__ == "__main__":
227
  demo.launch(
228
  ssr_mode=False,
229
  server_name="0.0.0.0",
230
  server_port=int(os.getenv("PORT", "7860")),
231
  share=False,
232
+ allowed_paths=["assets"], # ensure Space can serve local assets
233
  )