Spaces:
Paused
Paused
| import gradio as gr | |
| def create_ui(process_fn): | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# ๐ก๏ธ Self-Modifying Isolated AI") | |
| gr.Markdown("I run on CPU. I can install tools and change this UI.") | |
| # type="messages" ONLY works in Gradio 5+ | |
| chatbot = gr.Chatbot(height=400, type="messages") | |
| msg = gr.Textbox(label="Command or Chat") | |
| clear = gr.Button("Clear") | |
| def user(user_message, history): | |
| return "", history + [{"role": "user", "content": user_message}] | |
| def bot(history): | |
| user_message = history[-1]["content"] | |
| bot_message = process_fn(user_message) | |
| history.append({"role": "assistant", "content": bot_message}) | |
| return history | |
| msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then( | |
| bot, chatbot, chatbot | |
| ) | |
| clear.click(lambda: [], None, chatbot, queue=False) | |
| return demo |