Spaces:
Sleeping
Sleeping
import gradio as gr | |
import sys | |
import os | |
os.system("pip install -U gradio") | |
def execute_code(code): | |
try: | |
exec(code) | |
return "Code executed successfully!" | |
except Exception as e: | |
return f"Error: {str(e)}" | |
def execute_code_callback(code, temp, max): | |
return execute_code(code) | |
print("hello") | |
title = """Simple coding Demo""" | |
with gr.Blocks() as demo: | |
gr.Markdown(title) | |
prompt = gr.Code(label="Enter your code prompt", value="def print_hello_world():") | |
with gr.Row(): | |
temperature = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, value=0.5, label="Temperature") | |
max_length = gr.Slider(minimum=100, maximum=1024, step=10, value=450, label="Generate Length") | |
generate_btn = gr.Button("Try✨Coding") | |
output = gr.Code(label="✨Output:", lines=40) | |
generate_btn.click( | |
fn=execute_code_callback, | |
inputs=[prompt, temperature, max_length], | |
outputs=output | |
) | |
demo.launch() |