Spaces:
Running
Running
File size: 1,552 Bytes
751e7d4 085880a f7a9983 085880a 4b143e6 f7a9983 751e7d4 f7a9983 085880a f7a9983 085880a f7a9983 085880a 6159031 f7a9983 085880a |
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 42 43 44 45 46 47 |
import os
import gradio as gr
from huggingface_hub import InferenceClient
from e2b_code_interpreter import Sandbox
from utils import run_interactive_notebook
message_history = None
E2B_API_KEY = os.environ['E2B_API_KEY']
HF_TOKEN = os.environ['HF_TOKEN']
def execute_jupyter_agent(sytem_prompt, user_input):
client = InferenceClient(api_key=HF_TOKEN)
max_new_tokens = 512
model = "meta-llama/Llama-3.1-8B-Instruct"
sbx = Sandbox(api_key=E2B_API_KEY)
messages = [
{"role": "system", "content": "Environment: ipython\nYou are a helpful coding assistant. Always first explain what you are going to do before writing code."},
{"role": "user", "content": "What is 2+1? Use Python to solve."}
]
for notebook_html, messages in run_interactive_notebook(client, model, messages, sbx):
message_history = messages
yield notebook_html
# Create the interface
with gr.Blocks() as demo:
gr.Markdown("# HTML Generator")
with gr.Row():
system_input = gr.Textbox(label="System prompt", placeholder="Environment: ipython\nYou are a helpful coding assistant. Always first explain what you are going to do before writing code.")
user_input = gr.Textbox(label="User prompt", placeholder="What is 2+1? Use Python to solve.", lines=3)
generate_btn = gr.Button("Let's go!")
output = gr.HTML(label="Jupyter Notebook")
generate_btn.click(
fn=execute_jupyter_agent,
inputs=[system_input, user_input],
outputs=output
)
demo.launch() |