Alexandre Gazola commited on
Commit
46fb1b0
·
1 Parent(s): d0f5cd1
Files changed (2) hide show
  1. app.py +11 -2
  2. download_task_file.py +17 -2
app.py CHANGED
@@ -20,6 +20,7 @@ from image_to_text_tool import image_to_text
20
  from internet_search_tool import internet_search
21
  from botanical_classification_tool import get_botanical_classification
22
  from excel_parser_tool import parse_excel
 
23
 
24
  # (Keep Constants as is) ok!
25
  # --- Constants ---
@@ -53,8 +54,12 @@ class LangChainAgent:
53
 
54
  def __call__(self, question: str) -> str:
55
  print(f"LangChain agent received: {question[:50]}...")
 
 
 
56
  print("Waiting 60s before answering")
57
- time.sleep(60) # Delay for 60 seconds
 
58
  result = self.executor.invoke({
59
  "input": question,
60
  "chat_history": []
@@ -129,7 +134,11 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
129
  print(f"Skipping item with missing task_id or question: {item}")
130
  continue
131
  try:
132
- submitted_answer = agent(question_text)
 
 
 
 
133
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
134
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
135
  except Exception as e:
 
20
  from internet_search_tool import internet_search
21
  from botanical_classification_tool import get_botanical_classification
22
  from excel_parser_tool import parse_excel
23
+ from download_task_file import download_file_as_base64
24
 
25
  # (Keep Constants as is) ok!
26
  # --- Constants ---
 
54
 
55
  def __call__(self, question: str) -> str:
56
  print(f"LangChain agent received: {question[:50]}...")
57
+
58
+ download_file_as_base64
59
+
60
  print("Waiting 60s before answering")
61
+ time.sleep(15) # Delay for 60 seconds
62
+
63
  result = self.executor.invoke({
64
  "input": question,
65
  "chat_history": []
 
134
  print(f"Skipping item with missing task_id or question: {item}")
135
  continue
136
  try:
137
+ question_text_for_agent = question_text
138
+ if task_id:
139
+ base64_attatched_file = download_file_as_base64(task_id)
140
+ question_text_for_agent += f'. The content in base64 of the attatched file mentioned in the question is the following: {base64_attatched_file}'
141
+ submitted_answer = agent(question_text_for_agent)
142
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
143
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
144
  except Exception as e:
download_task_file.py CHANGED
@@ -1,5 +1,7 @@
1
  import os
2
  import requests
 
 
3
 
4
  def download_file(task_id: str):
5
  # Construct the URL
@@ -42,5 +44,18 @@ def download_file(task_id: str):
42
  else:
43
  print(f"Failed to download the file. Status code: {response.status_code}")
44
 
45
- task_id = "7bd855d8-463d-4ed5-93ca-5fe35145f733"
46
- download_file(task_id)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import requests
3
+ import requests
4
+ import base64
5
 
6
  def download_file(task_id: str):
7
  # Construct the URL
 
44
  else:
45
  print(f"Failed to download the file. Status code: {response.status_code}")
46
 
47
+ def download_file_as_base64(task_id: str) -> str:
48
+ # Construct the URL
49
+ url = f"https://agents-course-unit4-scoring.hf.space/files/{task_id}"
50
+
51
+ # Send the request to download the file
52
+ response = requests.get(url)
53
+
54
+ if response.status_code == 200:
55
+ # Encode the content to Base64
56
+ encoded_bytes = base64.b64encode(response.content)
57
+ encoded_str = encoded_bytes.decode('utf-8') # Convert bytes to string
58
+ return encoded_str
59
+ else:
60
+ raise Exception(f"Failed to download the file. Status code: {response.status_code}")
61
+