CindyDelage commited on
Commit
31ff456
·
verified ·
1 Parent(s): 99ff3ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -10
app.py CHANGED
@@ -77,16 +77,16 @@ class BasicAgent:
77
  "(2) If the question is in English, do not use the translator. Determine whether it requires a web search, "
78
  "and if so, use only the exact words from the question as keywords—no synonyms. "
79
  "(3) If a web search is needed and the answer is likely on Wikipedia, try using the wiki_url_tool to find the relevant page; "
80
- "if that fails, search manually; if you use wikipedia, always use the wiki_tool to extract data from Wikipedia tables. They always contain the answer to your question. Carefully read and analyze them to identify the relevant table and extract the correct information based on the context of your question. It may not contain the exact word you are searching for, but you will, by analysing the table content and mostly the headers, find the answer, always. Do not rely on any other sources. "
81
  "(4) Never use synonyms not present in the question. "
82
- "(5) Some questions may include an attached file or a download link. If a file is directly provided, use it immediately. Otherwise, download the file from the link before proceeding with any further steps. If it contains an image, use image_tool to describe it. If it contains an mp3 audio, use audio_tool to translate it to text."
83
  "(6) If you need to know the list of vegetables, you will find it with vegetable_info_retriever."
84
  "Never make assumptions to answer a question. . If you do not know the answer, say so clearly. Always report your thoughts and finish your answer with the following template: "
85
  "FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. "
86
  "If you are asked for a number, don’t use comma to write your number neither use units such as $ or percent sign unless specified otherwise. "
87
  "If you are asked for a string, don’t use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. "
88
  "If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string. "
89
- f"Here are the questions : {question} and the attached file (may be 'None', hence it means no attached file for this question) {file_name}"
90
  )
91
  answer = self.alfred.run(prompt)
92
  print(f"Agent returning fixed answer: {answer}")
@@ -150,18 +150,34 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
150
  for item in questions_data:
151
  task_id = item.get("task_id")
152
  question_text = item.get("question")
153
- file_url= f"{api_url}/files/{task_id}"
154
- file_name=item.get("file_name")
155
- if file_name!="":
156
- attached_file = requests.get(file_url)
157
- attached_file.raise_for_status()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  else:
159
- attached_file=None
160
  if not task_id or question_text is None:
161
  print(f"Skipping item with missing task_id or question: {item}")
162
  continue
163
  try:
164
- submitted_answer = agent(question_text,attached_file)
165
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
166
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
167
  except Exception as e:
 
77
  "(2) If the question is in English, do not use the translator. Determine whether it requires a web search, "
78
  "and if so, use only the exact words from the question as keywords—no synonyms. "
79
  "(3) If a web search is needed and the answer is likely on Wikipedia, try using the wiki_url_tool to find the relevant page; "
80
+ "if that fails, search manually; if you use wikipedia, always use the wiki_tool to extract data from Wikipedia tables. They always contain the answer to your question. Carefully read and analyze them to identify the relevant table and extract the correct information based on the context of your question. For each table, ask yourself the following question : Are the headers compatible with my question ? Is so, use the table. It may not contain the exact word you are searching for, but you will, by analysing the table content and mostly the headers, find the answer, always. Do not rely on any other sources. "
81
  "(4) Never use synonyms not present in the question. "
82
+ "(5) Some questions may include a path to an attached file. If it contains an image, use image_tool to describe it. If it contains an mp3 audio, use audio_tool to translate it to text."
83
  "(6) If you need to know the list of vegetables, you will find it with vegetable_info_retriever."
84
  "Never make assumptions to answer a question. . If you do not know the answer, say so clearly. Always report your thoughts and finish your answer with the following template: "
85
  "FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. "
86
  "If you are asked for a number, don’t use comma to write your number neither use units such as $ or percent sign unless specified otherwise. "
87
  "If you are asked for a string, don’t use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. "
88
  "If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string. "
89
+ f"Here are the questions : {question} and the attached file path (may be 'None', hence it means no attached file for this question) {file_name}"
90
  )
91
  answer = self.alfred.run(prompt)
92
  print(f"Agent returning fixed answer: {answer}")
 
150
  for item in questions_data:
151
  task_id = item.get("task_id")
152
  question_text = item.get("question")
153
+ file_name = item.get("file_name")
154
+ file_url = f"{api_url}/files/{task_id}"
155
+
156
+ attached_file_path = None
157
+
158
+ if file_name: # vérifie si file_name est non vide et non None
159
+ try:
160
+ response = requests.get(file_url)
161
+ response.raise_for_status()
162
+
163
+ # Sauvegarder le fichier dans un répertoire local temporaire ou dédié
164
+ attached_file_path = os.path.join("downloads", file_name)
165
+ os.makedirs("downloads", exist_ok=True)
166
+
167
+ with open(attached_file_path, "wb") as f:
168
+ f.write(response.content)
169
+
170
+ print(f"Fichier {file_name} téléchargé avec succès.")
171
+ except requests.exceptions.RequestException as e:
172
+ print(f"Erreur lors du téléchargement de {file_name} : {e}")
173
+ attached_file_path = None
174
  else:
175
+ print("Aucun fichier attaché.")
176
  if not task_id or question_text is None:
177
  print(f"Skipping item with missing task_id or question: {item}")
178
  continue
179
  try:
180
+ submitted_answer = agent(question_text,attached_file_path)
181
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
182
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
183
  except Exception as e: