Yongkang ZOU commited on
Commit
7cbe9e1
·
1 Parent(s): 9348b59

update app

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -3,18 +3,33 @@ import gradio as gr
3
  import requests
4
  import pandas as pd
5
 
 
 
 
6
  # --- Constants ---
7
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
8
 
9
  # --- Basic Agent Definition ---
10
  class BasicAgent:
11
- def __init__(self):
12
- print("BasicAgent initialized.")
 
 
13
  def __call__(self, question: str) -> str:
14
- print(f"Agent received question (first 50 chars): {question[:50]}...")
15
- fixed_answer = "This is a default answer."
16
- print(f"Agent returning fixed answer: {fixed_answer}")
17
- return fixed_answer
 
 
 
 
 
 
 
 
 
 
18
 
19
  def run_and_submit_all(username: str):
20
  if not username:
 
3
  import requests
4
  import pandas as pd
5
 
6
+ from agent import build_graph
7
+ from langchain_core.messages import HumanMessage
8
+
9
  # --- Constants ---
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
 
12
  # --- Basic Agent Definition ---
13
  class BasicAgent:
14
+ def __init__(self, provider: str = "groq"):
15
+ print(f"Initializing LangGraph Agent with provider: {provider}")
16
+ self.graph = build_graph(provider=provider)
17
+
18
  def __call__(self, question: str) -> str:
19
+ print(f"Running LangGraph Agent on question: {question[:50]}...")
20
+ try:
21
+ messages = [HumanMessage(content=question)]
22
+ result = self.graph.invoke({"messages": messages})
23
+ outputs = result["messages"]
24
+ for m in reversed(outputs):
25
+ if m.type == "ai":
26
+ print(f"Agent output: {m.content[:100]}")
27
+ return m.content
28
+ return "⚠️ No AI message found in the result."
29
+ except Exception as e:
30
+ print(f"LangGraph Agent error: {e}")
31
+ return f"❌ Error: {str(e)}"
32
+
33
 
34
  def run_and_submit_all(username: str):
35
  if not username: