Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -28,28 +28,20 @@ Always run the code at each step and repeat the steps if necessary until you rea
|
|
28 |
NEVER ASSUME, ALWAYS VERIFY!"""
|
29 |
|
30 |
|
31 |
-
def execute_jupyter_agent(sytem_prompt, user_input, max_new_tokens):
|
32 |
-
global message_history
|
33 |
client = InferenceClient(api_key=HF_TOKEN)
|
34 |
model = "meta-llama/Llama-3.1-8B-Instruct"
|
35 |
|
36 |
sbx = Sandbox(api_key=E2B_API_KEY)
|
37 |
|
38 |
# Initialize message_history if it doesn't exist
|
39 |
-
if
|
40 |
-
|
41 |
-
|
42 |
-
{"role": "user", "content": user_input}
|
43 |
-
]
|
44 |
-
else:
|
45 |
-
execute_jupyter_agent.message_history.append({"role": "user", "content": user_input})
|
46 |
-
|
47 |
-
print("history", execute_jupyter_agent.message_history)
|
48 |
-
|
49 |
|
50 |
-
for notebook_html,
|
51 |
-
|
52 |
-
yield notebook_html
|
53 |
|
54 |
|
55 |
css = """
|
@@ -71,7 +63,7 @@ css = """
|
|
71 |
|
72 |
# Create the interface
|
73 |
with gr.Blocks(css=css) as demo:
|
74 |
-
|
75 |
with gr.Row():
|
76 |
user_input = gr.Textbox(value="Solve the Lotka-Volterra equation and plot the results.", lines=3)
|
77 |
|
@@ -95,8 +87,8 @@ with gr.Blocks(css=css) as demo:
|
|
95 |
|
96 |
generate_btn.click(
|
97 |
fn=execute_jupyter_agent,
|
98 |
-
inputs=[system_input, user_input, max_tokens],
|
99 |
-
outputs=
|
100 |
)
|
101 |
|
102 |
demo.launch()
|
|
|
28 |
NEVER ASSUME, ALWAYS VERIFY!"""
|
29 |
|
30 |
|
31 |
+
def execute_jupyter_agent(sytem_prompt, user_input, max_new_tokens, message_history):
|
|
|
32 |
client = InferenceClient(api_key=HF_TOKEN)
|
33 |
model = "meta-llama/Llama-3.1-8B-Instruct"
|
34 |
|
35 |
sbx = Sandbox(api_key=E2B_API_KEY)
|
36 |
|
37 |
# Initialize message_history if it doesn't exist
|
38 |
+
if len(message_history)==0:
|
39 |
+
message_history.append({"role": "system", "content": sytem_prompt})
|
40 |
+
message_history.append({"role": "user", "content": user_input})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
for notebook_html, messages in run_interactive_notebook(client, model, message_history, sbx, max_new_tokens=max_new_tokens):
|
43 |
+
message_history = messages
|
44 |
+
yield notebook_html, message_history
|
45 |
|
46 |
|
47 |
css = """
|
|
|
63 |
|
64 |
# Create the interface
|
65 |
with gr.Blocks(css=css) as demo:
|
66 |
+
html_output = gr.HTML(value=update_notebook_display(create_base_notebook([])))
|
67 |
with gr.Row():
|
68 |
user_input = gr.Textbox(value="Solve the Lotka-Volterra equation and plot the results.", lines=3)
|
69 |
|
|
|
87 |
|
88 |
generate_btn.click(
|
89 |
fn=execute_jupyter_agent,
|
90 |
+
inputs=[system_input, user_input, max_tokens, gr.State(value=[])],
|
91 |
+
outputs=[html_output, gr.State()]
|
92 |
)
|
93 |
|
94 |
demo.launch()
|