Sandiago21 commited on
Commit
0e71be8
·
verified ·
1 Parent(s): ba2b951

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -3
app.py CHANGED
@@ -889,7 +889,7 @@ class BasicAgent:
889
  self.safe_app = safe_workflow.compile()
890
 
891
  print("BasicAgent initialized.")
892
- def __call__(self, question: str, filename: str) -> str:
893
  print(f"Agent received question (first 50 chars): {question[:50]}...")
894
  fixed_answer = "This is a default answer."
895
  # print(f"Agent returning fixed answer: {fixed_answer}")
@@ -909,7 +909,26 @@ class BasicAgent:
909
  if len(tokenizer.encode(state["messages"][::-1])) < len(tokenizer.encode(state["messages"])):
910
  state["messages"] = state["messages"][::-1]
911
 
912
- df = pd.read_excel(filename)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
913
 
914
  try:
915
  # response = self.safe_app.invoke(state)
@@ -1040,7 +1059,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
1040
  print(f"Skipping item with missing task_id or question: {item}")
1041
  continue
1042
  try:
1043
- submitted_answer = agent(question_text, filename)
1044
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
1045
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
1046
  except Exception as e:
 
889
  self.safe_app = safe_workflow.compile()
890
 
891
  print("BasicAgent initialized.")
892
+ def __call__(self, task_id: str, question: str, filename: str) -> str:
893
  print(f"Agent received question (first 50 chars): {question[:50]}...")
894
  fixed_answer = "This is a default answer."
895
  # print(f"Agent returning fixed answer: {fixed_answer}")
 
909
  if len(tokenizer.encode(state["messages"][::-1])) < len(tokenizer.encode(state["messages"])):
910
  state["messages"] = state["messages"][::-1]
911
 
912
+
913
+ # Replace with your actual API base URL
914
+ BASE_URL = f"{api_url}/files"
915
+
916
+ # Construct the full URL
917
+ url = f"{BASE_URL}/{task_id}"
918
+
919
+ # Send GET request
920
+ response = requests.get(url)
921
+
922
+ # Check if the request was successful
923
+ if response.status_code == 200:
924
+ # Save the content to a local file
925
+ with open("downloaded_file.xlsx", "wb") as f:
926
+ f.write(response.content)
927
+ print("File downloaded successfully!")
928
+ else:
929
+ print(f"Failed to download file: {response.status_code}")
930
+
931
+ df = pd.read_excel("downloaded_file.xlsx")
932
 
933
  try:
934
  # response = self.safe_app.invoke(state)
 
1059
  print(f"Skipping item with missing task_id or question: {item}")
1060
  continue
1061
  try:
1062
+ submitted_answer = agent(task_id, question_text, filename)
1063
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
1064
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
1065
  except Exception as e: