Spaces:
Sleeping
Sleeping
Commit
·
2cb6927
1
Parent(s):
932aa92
regex for final answer
Browse files
app.py
CHANGED
@@ -728,6 +728,17 @@ def max_object_in_video(video_url: str, object_label: str = "bird") -> str:
|
|
728 |
|
729 |
return f"Maximum {object_label} count in a single frame: {max_count}"
|
730 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
731 |
|
732 |
##-- Tool Discovery ---
|
733 |
# Use @tool for each function.
|
@@ -765,8 +776,8 @@ tool_descriptions = "\n".join(f"- {tool.name}: {tool.description}" for tool in t
|
|
765 |
# --- System Prompt for the Agent ---
|
766 |
|
767 |
system_prompt = f"""
|
768 |
-
You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: [YOUR FINAL ANSWER].
|
769 |
-
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
|
770 |
First check if you can answer the question by yourself without the need for a tool. If you can answer without hallucination then answer the question directly. If you cannot, use the tools provided to answer the question.
|
771 |
|
772 |
You also have access to a set of tools, which you can use to answer the question, if you can't answer the question directly. The available tools are:
|
@@ -944,7 +955,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
944 |
try:
|
945 |
# full_prompt = f"{system_prompt}\n Input Question: {question_text}"
|
946 |
# submitted_answer = agent.run(full_prompt)
|
947 |
-
|
|
|
948 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
949 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
950 |
except Exception as e:
|
|
|
728 |
|
729 |
return f"Maximum {object_label} count in a single frame: {max_count}"
|
730 |
|
731 |
+
def extract_final_answer(output: str) -> str:
|
732 |
+
# Try to extract answer after [YOUR FINAL ANSWER] or Final Answer:
|
733 |
+
match = re.search(r"\[YOUR FINAL ANSWER\]\s*(.+)", output)
|
734 |
+
if match:
|
735 |
+
return match.group(1).strip()
|
736 |
+
match = re.search(r"Final Answer:\s*(.+)", output)
|
737 |
+
if match:
|
738 |
+
return match.group(1).strip()
|
739 |
+
# Fallback: return the whole output if no match
|
740 |
+
return output.strip()
|
741 |
+
|
742 |
|
743 |
##-- Tool Discovery ---
|
744 |
# Use @tool for each function.
|
|
|
776 |
# --- System Prompt for the Agent ---
|
777 |
|
778 |
system_prompt = f"""
|
779 |
+
You are a general AI assistant. I will ask you a question. Report your thoughts as required, and finish your answer with the following template: [YOUR FINAL ANSWER].
|
780 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings, and should not include any explanations, thoughts, or tool calls. Don't give output anything else except the final answer.
|
781 |
First check if you can answer the question by yourself without the need for a tool. If you can answer without hallucination then answer the question directly. If you cannot, use the tools provided to answer the question.
|
782 |
|
783 |
You also have access to a set of tools, which you can use to answer the question, if you can't answer the question directly. The available tools are:
|
|
|
955 |
try:
|
956 |
# full_prompt = f"{system_prompt}\n Input Question: {question_text}"
|
957 |
# submitted_answer = agent.run(full_prompt)
|
958 |
+
submitted_answer_raw = agent.run(question_text)
|
959 |
+
submitted_answer = extract_final_answer(submitted_answer_raw)
|
960 |
answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
|
961 |
results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
|
962 |
except Exception as e:
|