diamond-in commited on
Commit
a5b4b0e
·
verified ·
1 Parent(s): 66dca47

Update ui_layout.py

Browse files
Files changed (1) hide show
  1. ui_layout.py +1 -13
ui_layout.py CHANGED
@@ -1,40 +1,28 @@
1
  import gradio as gr
2
 
3
  def create_ui(process_fn):
4
- """
5
- The AI can rewrite this function to change the UI.
6
- Updated for Gradio 5+ (Messages format).
7
- """
8
  with gr.Blocks() as demo:
9
  gr.Markdown("# 🛡️ Self-Modifying Isolated AI")
10
  gr.Markdown("I run on CPU. I can install tools and change this UI.")
11
 
12
- # type="messages" is REQUIRED for Gradio 5
13
  chatbot = gr.Chatbot(height=400, type="messages")
14
 
15
  msg = gr.Textbox(label="Command or Chat")
16
  clear = gr.Button("Clear")
17
 
18
  def user(user_message, history):
19
- # Append user message in the new dictionary format
20
  return "", history + [{"role": "user", "content": user_message}]
21
 
22
  def bot(history):
23
- # Get the content of the last message (User's message)
24
  user_message = history[-1]["content"]
25
-
26
- # Call the AI process function
27
  bot_message = process_fn(user_message)
28
-
29
- # Append the assistant's response
30
  history.append({"role": "assistant", "content": bot_message})
31
  return history
32
 
33
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
34
  bot, chatbot, chatbot
35
  )
36
-
37
- # Clear button resets history to an empty list
38
  clear.click(lambda: [], None, chatbot, queue=False)
39
 
40
  return demo
 
1
  import gradio as gr
2
 
3
  def create_ui(process_fn):
 
 
 
 
4
  with gr.Blocks() as demo:
5
  gr.Markdown("# 🛡️ Self-Modifying Isolated AI")
6
  gr.Markdown("I run on CPU. I can install tools and change this UI.")
7
 
8
+ # type="messages" ONLY works in Gradio 5+
9
  chatbot = gr.Chatbot(height=400, type="messages")
10
 
11
  msg = gr.Textbox(label="Command or Chat")
12
  clear = gr.Button("Clear")
13
 
14
  def user(user_message, history):
 
15
  return "", history + [{"role": "user", "content": user_message}]
16
 
17
  def bot(history):
 
18
  user_message = history[-1]["content"]
 
 
19
  bot_message = process_fn(user_message)
 
 
20
  history.append({"role": "assistant", "content": bot_message})
21
  return history
22
 
23
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
24
  bot, chatbot, chatbot
25
  )
 
 
26
  clear.click(lambda: [], None, chatbot, queue=False)
27
 
28
  return demo