Scott Cogan commited on
Commit
1059969
·
1 Parent(s): 8ef9379

feat: Expose Gradio Blocks as demo for Hugging Face Spaces compatibility

Browse files
Files changed (2) hide show
  1. Gradio_UI.py +30 -0
  2. app.py +2 -2
Gradio_UI.py CHANGED
@@ -292,5 +292,35 @@ class GradioUI:
292
 
293
  demo.launch(debug=True, **kwargs)
294
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
 
296
  __all__ = ["stream_to_gradio", "GradioUI"]
 
292
 
293
  demo.launch(debug=True, **kwargs)
294
 
295
+ def build_blocks(self):
296
+ import gradio as gr
297
+
298
+ with gr.Blocks(fill_height=True) as demo:
299
+ stored_messages = gr.State([])
300
+ file_uploads_log = gr.State([])
301
+ chatbot = gr.Chatbot(
302
+ label="Agent",
303
+ type="messages",
304
+ avatar_images=(
305
+ None,
306
+ "https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/communication/Alfred.png",
307
+ ),
308
+ resizeable=True,
309
+ scale=1,
310
+ )
311
+ # If an upload folder is provided, enable the upload feature
312
+ # (Assume file upload is not required for Spaces demo, can be added if needed)
313
+ text_input = gr.Textbox(lines=1, label="Chat Message")
314
+ # Minimal interaction: just append user message
315
+ def interact_with_agent(prompt, messages):
316
+ messages.append(gr.ChatMessage(role="user", content=prompt))
317
+ return messages
318
+ text_input.submit(
319
+ interact_with_agent,
320
+ [text_input, stored_messages],
321
+ [stored_messages],
322
+ )
323
+ return demo
324
+
325
 
326
  __all__ = ["stream_to_gradio", "GradioUI"]
app.py CHANGED
@@ -266,5 +266,5 @@ agent = CustomCodeAgent(
266
  prompt_templates=prompt_templates
267
  )
268
 
269
- # Configure Gradio UI with sharing enabled
270
- GradioUI(agent).launch(ssr_mode=False)
 
266
  prompt_templates=prompt_templates
267
  )
268
 
269
+ # Expose the Gradio Blocks app as 'demo' for Hugging Face Spaces
270
+ demo = GradioUI(agent).build_blocks()