Spaces:
Sleeping
Sleeping
File size: 1,316 Bytes
114d818 f80e4d3 114d818 f80e4d3 114d818 f80e4d3 114d818 f80e4d3 114d818 f80e4d3 114d818 f80e4d3 114d818 f80e4d3 114d818 f80e4d3 114d818 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
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() |