samoye16 commited on
Commit
a5e18fe
verified
1 Parent(s): 785830b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -62
app.py CHANGED
@@ -3,78 +3,29 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
 
6
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
-
12
- class WikipediaSearchTool:
13
- def search(self, query: str) -> str:
14
- if "Mercedes Sosa" in query:
15
- return """Between 2000 and 2009, Mercedes Sosa released the following studio albums:
16
- - Coraz贸n Libre (2005)
17
- - Cantora 1 (2009)
18
- - Cantora 2 (2009)
19
- """
20
- return "No information found."
21
-
22
  # --- Basic Agent Definition ---
23
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
24
  class BasicAgent:
 
25
  def __init__(self):
26
- self.wikipedia_tool = WikipediaSearchTool()
27
  print("BasicAgent initialized.")
28
-
 
29
  def __call__(self, question: str) -> str:
30
- print(f"Agent received question: {question}")
31
-
32
- if "studio albums" in question and "Mercedes Sosa" in question:
33
- wiki_text = self.wikipedia_tool.search("Mercedes Sosa studio albums between 2000 and 2009")
34
- album_list = self.extract_albums(wiki_text)
35
- album_count = len(album_list)
36
- return str(album_count)
37
- elif "Featured Article" in question and "November 2016" in question:
38
- return str("FunkMonk")
39
- elif "table defining" in question:
40
- return str("b,e")
41
- elif "1htKBjuUWec" in question:
42
- return str("Extremely")
43
- elif "CK-12 license" in question:
44
- return str("Louvrier")
45
- elif "L1vXCYZAYYM" in question:
46
- return str(3)
47
- elif "tfel" in question:
48
- return str("right")
49
- elif "grocery list" in question:
50
- return str("broccoli, celery, fresh basil, lettuce, sweet potatoes")
51
- elif "Yankee " in question:
52
- return str(519)
53
- elif "Carolyn Collins Petersen" in question:
54
- return str("80GSFC21M0002")
55
- elif "Vietnamese specimens" in question:
56
- return str("Saint Petersburg")
57
- elif "CK-12 license" in question:
58
- return str("Louvrier")
59
- elif "Everybody Loves Raymond" in question:
60
- return str("Wojciech")
61
- elif "Homework.mp3" in question:
62
- return str("132, 133, 134, 197, 245")
63
- elif "fast-food chain" in question:
64
- return str(89706.00)
65
- elif "Olympics" in question:
66
- return str("CUB")
67
- elif "pitchers" in question and "Taish艒 Tamai" in question:
68
- return str("Yoshida, Uehara")
69
- elif "Malko Competition" in question:
70
- return str("Dmitry")
71
- else:
72
- return "This is a default answer."
73
-
74
- def extract_albums(self, wiki_text: str) -> list:
75
- lines = wiki_text.split("\n")
76
- albums = [line.strip() for line in lines if "-" in line]
77
- return albums
78
 
79
  def run_and_submit_all( profile: gr.OAuthProfile | None):
80
  """
@@ -248,4 +199,4 @@ if __name__ == "__main__":
248
  print("-"*(60 + len(" App Starting ")) + "\n")
249
 
250
  print("Launching Gradio Interface for Basic Agent Evaluation...")
251
- demo.launch(debug=True, share=False)
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from agents import create_agent_flow
7
+ from langchain_core.messages import HumanMessage
8
 
9
  # (Keep Constants as is)
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
 
 
 
 
 
 
 
 
 
 
 
13
  # --- Basic Agent Definition ---
14
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
15
  class BasicAgent:
16
+
17
  def __init__(self):
 
18
  print("BasicAgent initialized.")
19
+ self.agent = create_agent_flow()
20
+
21
  def __call__(self, question: str) -> str:
22
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
23
+
24
+ question = [HumanMessage(content=question)]
25
+ question_ask = self.agent.invoke({"messages": question})
26
+ response = question_ask['messages'][-1].content
27
+ print(f"Agent returning fixed answer: {response}")
28
+ return response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  def run_and_submit_all( profile: gr.OAuthProfile | None):
31
  """
 
199
  print("-"*(60 + len(" App Starting ")) + "\n")
200
 
201
  print("Launching Gradio Interface for Basic Agent Evaluation...")
202
+ demo.launch(debug=True, share=False)