ai-canvas / app.py
parrotmaker's picture
Update app.py
f80e4d3 verified
raw
history blame
1.32 kB
import gradio as gr
# Placeholder assistant function
def assistant_response(message):
return f"🧠 Assistant: You said '{message}'"
# (Optional) Run code
def run_code(code):
try:
exec_globals = {}
exec(code, exec_globals)
return "βœ… Code executed successfully (no visible output)"
except Exception as e:
return f"❌ Error:\n{e}"
with gr.Blocks() as demo:
with gr.Row():
# LEFT COLUMN - AI CHAT
with gr.Column(scale=1):
gr.Markdown("### πŸ€– AI Assistant")
chat = gr.Chatbot()
msg = gr.Textbox(placeholder="Ask for help...", label="Your Message")
send = gr.Button("Send")
def handle_chat(user_message, history):
reply = assistant_response(user_message)
history.append((user_message, reply))
return "", history
send.click(handle_chat, [msg, chat], [msg, chat])
# RIGHT COLUMN - CODE EDITOR
with gr.Column(scale=2):
gr.Markdown("### πŸ’» Code Canvas")
editor = gr.Code(label="Your Code Here", language="python")
run_btn = gr.Button("Run Code")
output = gr.Textbox(label="Output")
run_btn.click(run_code, inputs=editor, outputs=output)
demo.launch()