gabejavitt commited on
Commit
24a656d
·
verified ·
1 Parent(s): a7f41e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -780,6 +780,9 @@ class PlanningReflectionAgent:
780
  HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
781
  if not HUGGINGFACEHUB_API_TOKEN:
782
  raise ValueError("HUGGINGFACEHUB_API_TOKEN secret is not set! Please add it to your Space secrets.")
 
 
 
783
 
784
  self.tools = defined_tools
785
 
@@ -1265,17 +1268,26 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
1265
  else:
1266
  print("User not logged in.")
1267
  return "Please Login to Hugging Face with the button.", None
1268
-
 
 
 
 
 
 
 
 
 
1269
  api_url = DEFAULT_API_URL
1270
  questions_url = f"{api_url}/questions"
1271
  submit_url = f"{api_url}/submit"
1272
 
1273
  # 1. Instantiate Agent ( modify this part to create your agent)
1274
- try:
1275
- agent = BasicAgent()
1276
- except Exception as e:
1277
- print(f"Error instantiating agent: {e}")
1278
- return f"Error initializing agent: {e}", None
1279
  # In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
1280
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
1281
  print(agent_code)
 
780
  HUGGINGFACEHUB_API_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
781
  if not HUGGINGFACEHUB_API_TOKEN:
782
  raise ValueError("HUGGINGFACEHUB_API_TOKEN secret is not set! Please add it to your Space secrets.")
783
+ GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
784
+ if not GOOGLE_API_KEY:
785
+ raise ValueError("GOOGLE_API_KEY not set!")
786
 
787
  self.tools = defined_tools
788
 
 
1268
  else:
1269
  print("User not logged in.")
1270
  return "Please Login to Hugging Face with the button.", None
1271
+ # Use the globally instantiated agent
1272
+ global agent
1273
+
1274
+ if agent is None:
1275
+ error_msg = "FATAL: Agent failed to initialize at startup. Check logs for errors."
1276
+ print(error_msg)
1277
+ return error_msg, None
1278
+
1279
+ print("✅ Using globally instantiated PlanningReflectionAgent")
1280
+
1281
  api_url = DEFAULT_API_URL
1282
  questions_url = f"{api_url}/questions"
1283
  submit_url = f"{api_url}/submit"
1284
 
1285
  # 1. Instantiate Agent ( modify this part to create your agent)
1286
+ #try:
1287
+ # agent = BasicAgent()
1288
+ #except Exception as e:
1289
+ # print(f"Error instantiating agent: {e}")
1290
+ # return f"Error initializing agent: {e}", None
1291
  # In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
1292
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
1293
  print(agent_code)