devasurya commited on
Commit
2e8e56f
·
verified ·
1 Parent(s): e9eca0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -3,8 +3,10 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
 
 
6
 
7
- from my_agent import agent
8
 
9
  # (Keep Constants as is)
10
  # --- Constants ---
@@ -15,11 +17,18 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
15
  class BasicAgent:
16
  def __init__(self):
17
  print("BasicAgent initialized.")
18
- def __call__(self, question: str) -> str:
19
  print(f"Agent received question (first 50 chars): {question[:50]}...")
20
- agent_response = agent.run(question)
 
 
 
 
 
 
 
21
  print(f"Agent returning fixed answer: {agent_response}")
22
- return str(agent_response).strip()
23
 
24
  def run_and_submit_all( profile: gr.OAuthProfile | None):
25
  """
@@ -112,7 +121,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
112
  print(f"Skipping item with missing task_id or question: {item}")
113
  continue
114
  try:
115
- submitted_answer = agent(question_text)
116
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
117
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
118
  except Exception as e:
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from langchain_core.messages import HumanMessage
7
+
8
+ from langgraph_agent import react_agent
9
 
 
10
 
11
  # (Keep Constants as is)
12
  # --- Constants ---
 
17
  class BasicAgent:
18
  def __init__(self):
19
  print("BasicAgent initialized.")
20
+ def __call__(self, question: str, file_path: str) -> str:
21
  print(f"Agent received question (first 50 chars): {question[:50]}...")
22
+ #agent_response = agent.run(question)
23
+ config = {"configurable": {}}
24
+ if file_path:
25
+ config = {"configurable": {"file_path": file_path}}
26
+ messages = [HumanMessage(content=f"{question}")]
27
+ agent_response = react_agent.invoke({"messages": messages}, config=config, debug=True)
28
+ agent_response = agent_response["messages"][-1].content
29
+ agent_response = agent_response.strip()
30
  print(f"Agent returning fixed answer: {agent_response}")
31
+ return agent_response
32
 
33
  def run_and_submit_all( profile: gr.OAuthProfile | None):
34
  """
 
121
  print(f"Skipping item with missing task_id or question: {item}")
122
  continue
123
  try:
124
+ submitted_answer = agent(question_text, file_path)
125
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
126
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
127
  except Exception as e: