Spaces:
Sleeping
Sleeping
correct final answer submission
Browse files- app.py +3 -2
- qa_graph.py +33 -20
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
-
from qa_graph import build_graph, Question
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
@@ -23,7 +23,8 @@ class BasicAgent:
|
|
| 23 |
messages = self.graph.invoke({"question": question, "decision": "",
|
| 24 |
"answer": ""})
|
| 25 |
answer = messages['answer']
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 29 |
"""
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from qa_graph import build_graph, Question, extract_final_answer
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
|
|
| 23 |
messages = self.graph.invoke({"question": question, "decision": "",
|
| 24 |
"answer": ""})
|
| 25 |
answer = messages['answer']
|
| 26 |
+
answer = extract_final_answer(answer)[1]
|
| 27 |
+
return answer
|
| 28 |
|
| 29 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 30 |
"""
|
qa_graph.py
CHANGED
|
@@ -3,6 +3,7 @@ from langgraph.graph import START, StateGraph, END
|
|
| 3 |
from typing import TypedDict
|
| 4 |
from agents import general_agent, excel_supervisor, video_supervisor
|
| 5 |
import os
|
|
|
|
| 6 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 7 |
os.environ["OPENAI_API_KEY"] = str(OPENAI_API_KEY)
|
| 8 |
|
|
@@ -183,7 +184,17 @@ def build_graph():
|
|
| 183 |
|
| 184 |
react_graph = builder.compile()
|
| 185 |
return react_graph
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
if __name__ == "__main__":
|
| 188 |
test = [
|
| 189 |
{
|
|
@@ -191,25 +202,27 @@ if __name__ == "__main__":
|
|
| 191 |
"question": "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.",
|
| 192 |
"Level": "1",
|
| 193 |
"file_name": ""
|
| 194 |
-
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
]
|
| 196 |
|
| 197 |
questions = [Question(**item) for item in test]
|
| 198 |
-
for
|
| 199 |
-
print(
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
print(result)
|
| 213 |
-
|
| 214 |
-
print(f"Answer: {result['answer']}")
|
| 215 |
-
print("-" * 50)
|
|
|
|
| 3 |
from typing import TypedDict
|
| 4 |
from agents import general_agent, excel_supervisor, video_supervisor
|
| 5 |
import os
|
| 6 |
+
from typing import List
|
| 7 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 8 |
os.environ["OPENAI_API_KEY"] = str(OPENAI_API_KEY)
|
| 9 |
|
|
|
|
| 184 |
|
| 185 |
react_graph = builder.compile()
|
| 186 |
return react_graph
|
| 187 |
+
def extract_final_answer(text: str) -> str|List[str]:
|
| 188 |
+
"""Extract the final answer from a string containing 'FINAL ANSWER: answer'"""
|
| 189 |
+
|
| 190 |
+
# Method 1: Simple string split (most common case)
|
| 191 |
+
if "FINAL ANSWER:" in text:
|
| 192 |
+
# Split on "FINAL ANSWER:" and take the part after it
|
| 193 |
+
parts = text.split("FINAL ANSWER:", 1) # Split only on first occurrence
|
| 194 |
+
return parts
|
| 195 |
+
else:
|
| 196 |
+
return "FINAL ANSWER: unknown"
|
| 197 |
+
|
| 198 |
if __name__ == "__main__":
|
| 199 |
test = [
|
| 200 |
{
|
|
|
|
| 202 |
"question": "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia.",
|
| 203 |
"Level": "1",
|
| 204 |
"file_name": ""
|
| 205 |
+
},
|
| 206 |
+
{
|
| 207 |
+
"task_id": "99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3",
|
| 208 |
+
"question": "Hi, I'm making a pie but I could use some help with my shopping list. I have everything I need for the crust, but I'm not sure about the filling. I got the recipe from my friend Aditi, but she left it as a voice memo and the speaker on my phone is buzzing so I can't quite make out what she's saying. Could you please listen to the recipe and list all of the ingredients that my friend described? I only want the ingredients for the filling, as I have everything I need to make my favorite pie crust. I've attached the recipe as Strawberry pie.mp3.\n\nIn your response, please only list the ingredients, not any measurements. So if the recipe calls for \"a pinch of salt\" or \"two cups of ripe strawberries\" the ingredients on the list would be \"salt\" and \"ripe strawberries\".\n\nPlease format your response as a comma separated list of ingredients. Also, please alphabetize the ingredients.",
|
| 209 |
+
"Level": "1",
|
| 210 |
+
"file_name": "99c9cc74-fdc8-46c6-8f8d-3ce2d3bfeea3.mp3"
|
| 211 |
+
}
|
| 212 |
]
|
| 213 |
|
| 214 |
questions = [Question(**item) for item in test]
|
| 215 |
+
for i, question in enumerate(questions):
|
| 216 |
+
print(f"\n{i}. {question.question}")
|
| 217 |
+
|
| 218 |
+
react_graph = build_graph()
|
| 219 |
+
# Invoke the graph and capture the result
|
| 220 |
+
result = react_graph.invoke({
|
| 221 |
+
"question": question,
|
| 222 |
+
"decision": "",
|
| 223 |
+
"answer": ""
|
| 224 |
+
})
|
| 225 |
+
answer = result['answer']
|
| 226 |
+
print(answer)
|
| 227 |
+
answer = extract_final_answer(answer)[1]
|
| 228 |
+
print(answer)
|
|
|
|
|
|
|
|
|
|
|
|