Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ import gradio as gr
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
|
|
|
|
6 |
|
7 |
# (Keep Constants as is)
|
8 |
# --- Constants ---
|
@@ -10,14 +12,15 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
10 |
|
11 |
# --- Basic Agent Definition ---
|
12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
13 |
-
class
|
14 |
def __init__(self):
|
15 |
-
print("
|
16 |
def __call__(self, question: str) -> str:
|
17 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
21 |
|
22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
23 |
"""
|
@@ -40,7 +43,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
40 |
|
41 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
42 |
try:
|
43 |
-
agent =
|
44 |
except Exception as e:
|
45 |
print(f"Error instantiating agent: {e}")
|
46 |
return f"Error initializing agent: {e}", None
|
|
|
3 |
import requests
|
4 |
import inspect
|
5 |
import pandas as pd
|
6 |
+
from langchain_core.messages import HumanMessage
|
7 |
+
from agent import build_graph
|
8 |
|
9 |
# (Keep Constants as is)
|
10 |
# --- Constants ---
|
|
|
12 |
|
13 |
# --- Basic Agent Definition ---
|
14 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
15 |
+
class AdvancedAIAgent:
|
16 |
def __init__(self):
|
17 |
+
print("AdvancedAIAgent initialized.")
|
18 |
def __call__(self, question: str) -> str:
|
19 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
20 |
+
messages = [HumanMessage(content=question)]
|
21 |
+
messages = self.graph.invoke({"messages": messages})
|
22 |
+
answer = messages['messages'][-1].content
|
23 |
+
return answer[14:]
|
24 |
|
25 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
26 |
"""
|
|
|
43 |
|
44 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
45 |
try:
|
46 |
+
agent = AdvancedAIAgent()
|
47 |
except Exception as e:
|
48 |
print(f"Error instantiating agent: {e}")
|
49 |
return f"Error initializing agent: {e}", None
|