Commit
·
c91fcfb
1
Parent(s):
549edad
check
Browse files
app.py
CHANGED
|
@@ -25,13 +25,19 @@ class BasicAgent:
|
|
| 25 |
print("BasicAgent initialized.")
|
| 26 |
async def aquery(self, question: str) -> str:
|
| 27 |
messages = [HumanMessage(content=question)]
|
| 28 |
-
# messages = self.agent.invoke({"messages": messages}, config={"callbacks": [langfuse_handler]})
|
| 29 |
-
|
| 30 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# Global cache for answers (in-memory)
|
| 37 |
cached_answers = None
|
|
@@ -49,7 +55,7 @@ async def generate_answers(profile: gr.OAuthProfile | None, progress=gr.Progress
|
|
| 49 |
print(f"User logged in: {username}")
|
| 50 |
else:
|
| 51 |
print("User not logged in.")
|
| 52 |
-
return "Please Login to Hugging Face with the button.", None, gr.update(interactive=False)
|
| 53 |
api_url = DEFAULT_API_URL
|
| 54 |
questions_url = f"{api_url}/questions"
|
| 55 |
try:
|
|
@@ -58,11 +64,11 @@ async def generate_answers(profile: gr.OAuthProfile | None, progress=gr.Progress
|
|
| 58 |
questions_data = response.json()
|
| 59 |
if not questions_data:
|
| 60 |
print("Fetched questions list is empty.")
|
| 61 |
-
return "Fetched questions list is empty or invalid format.", None, gr.update(interactive=False)
|
| 62 |
print(f"Fetched {len(questions_data)} questions.")
|
| 63 |
except Exception as e:
|
| 64 |
print(f"Error fetching questions: {e}")
|
| 65 |
-
return f"Error fetching questions: {e}", None, gr.update(interactive=False)
|
| 66 |
agent = BasicAgent()
|
| 67 |
results_log = []
|
| 68 |
answers_payload = []
|
|
@@ -96,7 +102,7 @@ async def generate_answers(profile: gr.OAuthProfile | None, progress=gr.Progress
|
|
| 96 |
cached_results_log = results_log
|
| 97 |
progress(100, desc="Done.")
|
| 98 |
results_df = pd.DataFrame(results_log)
|
| 99 |
-
return "Answer generation complete. Review and submit.", results_df, gr.update(interactive=True)
|
| 100 |
|
| 101 |
def submit_answers(profile: gr.OAuthProfile | None):
|
| 102 |
"""
|
|
|
|
| 25 |
print("BasicAgent initialized.")
|
| 26 |
async def aquery(self, question: str) -> str:
|
| 27 |
messages = [HumanMessage(content=question)]
|
|
|
|
|
|
|
| 28 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 29 |
+
try:
|
| 30 |
+
response = await self.agent.invoke({"messages": messages}, config={"callbacks": [langfuse_handler]})
|
| 31 |
+
print(f"Agent raw response: {response}")
|
| 32 |
+
if not response or 'messages' not in response or not response['messages']:
|
| 33 |
+
print("Agent response missing or empty 'messages'. Returning AGENT ERROR.")
|
| 34 |
+
return "AGENT ERROR: No response from agent."
|
| 35 |
+
answer = response['messages'][-1].content
|
| 36 |
+
print(f"Agent returning answer: {answer}")
|
| 37 |
+
return answer
|
| 38 |
+
except Exception as e:
|
| 39 |
+
print(f"Exception in aquery: {e}")
|
| 40 |
+
return f"AGENT ERROR: {e}"
|
| 41 |
|
| 42 |
# Global cache for answers (in-memory)
|
| 43 |
cached_answers = None
|
|
|
|
| 55 |
print(f"User logged in: {username}")
|
| 56 |
else:
|
| 57 |
print("User not logged in.")
|
| 58 |
+
return "Please Login to Hugging Face with the button.", None, gr.update(interactive=False)
|
| 59 |
api_url = DEFAULT_API_URL
|
| 60 |
questions_url = f"{api_url}/questions"
|
| 61 |
try:
|
|
|
|
| 64 |
questions_data = response.json()
|
| 65 |
if not questions_data:
|
| 66 |
print("Fetched questions list is empty.")
|
| 67 |
+
return "Fetched questions list is empty or invalid format.", None, gr.update(interactive=False)
|
| 68 |
print(f"Fetched {len(questions_data)} questions.")
|
| 69 |
except Exception as e:
|
| 70 |
print(f"Error fetching questions: {e}")
|
| 71 |
+
return f"Error fetching questions: {e}", None, gr.update(interactive=False)
|
| 72 |
agent = BasicAgent()
|
| 73 |
results_log = []
|
| 74 |
answers_payload = []
|
|
|
|
| 102 |
cached_results_log = results_log
|
| 103 |
progress(100, desc="Done.")
|
| 104 |
results_df = pd.DataFrame(results_log)
|
| 105 |
+
return "Answer generation complete. Review and submit.", results_df, gr.update(interactive=True)
|
| 106 |
|
| 107 |
def submit_answers(profile: gr.OAuthProfile | None):
|
| 108 |
"""
|