lvwerra HF staff commited on
Commit
3b5590f
·
verified ·
1 Parent(s): 5b8a275

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -2,6 +2,7 @@ import os
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
  from e2b_code_interpreter import Sandbox
 
5
 
6
  from utils import run_interactive_notebook, create_base_notebook, update_notebook_display
7
 
@@ -25,7 +26,10 @@ Follow these steps given a new task and dataset:
25
  5. If there is an issue with the code, reason about potential issues and then propose a solution and execute again the fixed code and check the result.
26
  Always run the code at each step and repeat the steps if necessary until you reach a solution.
27
 
28
- NEVER ASSUME, ALWAYS VERIFY!"""
 
 
 
29
 
30
 
31
  def execute_jupyter_agent(sytem_prompt, user_input, max_new_tokens, model,files, message_history):
@@ -34,14 +38,20 @@ def execute_jupyter_agent(sytem_prompt, user_input, max_new_tokens, model,files,
34
 
35
  sbx = Sandbox(api_key=E2B_API_KEY)
36
 
 
 
37
  for filepath in files:
 
38
  with open(filepath, "rb") as file:
39
  print(f"uploading {filepath}...")
40
- sbx.files.write(filepath, file)
 
 
41
 
 
42
  # Initialize message_history if it doesn't exist
43
  if len(message_history)==0:
44
- message_history.append({"role": "system", "content": sytem_prompt})
45
  message_history.append({"role": "user", "content": user_input})
46
 
47
  print("history:", message_history)
 
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
  from e2b_code_interpreter import Sandbox
5
+ from pathlib import Path
6
 
7
  from utils import run_interactive_notebook, create_base_notebook, update_notebook_display
8
 
 
26
  5. If there is an issue with the code, reason about potential issues and then propose a solution and execute again the fixed code and check the result.
27
  Always run the code at each step and repeat the steps if necessary until you reach a solution.
28
 
29
+ NEVER ASSUME, ALWAYS VERIFY!
30
+
31
+ List of available files:
32
+ {}"""
33
 
34
 
35
  def execute_jupyter_agent(sytem_prompt, user_input, max_new_tokens, model,files, message_history):
 
38
 
39
  sbx = Sandbox(api_key=E2B_API_KEY)
40
 
41
+ filenames = []
42
+
43
  for filepath in files:
44
+ filpath = Path(filepath)
45
  with open(filepath, "rb") as file:
46
  print(f"uploading {filepath}...")
47
+ sbx.files.write(filpath.name, file)
48
+ filenames.append(filpath.name)
49
+
50
 
51
+
52
  # Initialize message_history if it doesn't exist
53
  if len(message_history)==0:
54
+ message_history.append({"role": "system", "content": sytem_prompt.format("- " + "\n- ".join(filenames))})
55
  message_history.append({"role": "user", "content": user_input})
56
 
57
  print("history:", message_history)