Update app.py
Browse files
app.py
CHANGED
|
@@ -3,21 +3,51 @@ 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 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
print("BasicAgent initialized.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 18 |
-
|
| 19 |
-
print(f"Agent returning
|
| 20 |
-
return
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
@@ -150,6 +180,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 150 |
# return status_message, results_df
|
| 151 |
|
| 152 |
|
|
|
|
| 153 |
# --- Build Gradio Interface using Blocks ---
|
| 154 |
with gr.Blocks() as demo:
|
| 155 |
gr.Markdown("# Basic Agent Evaluation Runner")
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
#from tavily import TavilyClient
|
| 7 |
+
from langchain_tavily import TavilySearch
|
| 8 |
+
from langgraph.prebuilt import create_react_agent
|
| 9 |
+
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
| 10 |
|
| 11 |
# (Keep Constants as is)
|
| 12 |
# --- Constants ---
|
| 13 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 14 |
|
| 15 |
+
def _set_if_undefined(var: str):
|
| 16 |
+
if not os.environ.get(var):
|
| 17 |
+
os.environ[var] = userdata.get(var)
|
| 18 |
+
|
| 19 |
+
_set_if_undefined("TAVILY_API_KEY")
|
| 20 |
+
_set_if_undefined("HUGGINGFACEHUB_API_TOKEN")
|
| 21 |
+
|
| 22 |
# --- Basic Agent Definition ---
|
| 23 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 24 |
class BasicAgent:
|
| 25 |
def __init__(self):
|
| 26 |
print("BasicAgent initialized.")
|
| 27 |
+
|
| 28 |
+
# Generate the chat interface, including the tools
|
| 29 |
+
llm = HuggingFaceEndpoint(
|
| 30 |
+
repo_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 31 |
+
huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN,
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# Initialize Tavily Search Tool
|
| 35 |
+
tavily_search_tool = TavilySearch(
|
| 36 |
+
max_results=5,
|
| 37 |
+
topic="general",
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
agent = create_react_agent(llm, [tavily_search_tool])
|
| 41 |
+
|
| 42 |
+
# chat = ChatHuggingFace(llm=llm, verbose=True)
|
| 43 |
+
# tools = [search_web_tool]
|
| 44 |
+
# chat_with_tools = chat.bind_tools(tools)
|
| 45 |
+
|
| 46 |
def __call__(self, question: str) -> str:
|
| 47 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 48 |
+
answer = agent.invoke({"messages": [{"role": "user", "content": question}]})
|
| 49 |
+
print(f"Agent returning answer: {answer}")
|
| 50 |
+
return answer
|
| 51 |
|
| 52 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 53 |
"""
|
|
|
|
| 180 |
# return status_message, results_df
|
| 181 |
|
| 182 |
|
| 183 |
+
|
| 184 |
# --- Build Gradio Interface using Blocks ---
|
| 185 |
with gr.Blocks() as demo:
|
| 186 |
gr.Markdown("# Basic Agent Evaluation Runner")
|