Spaces:
Build error
Build error
Update app.py
Browse files3 unmodified lines45678914 unmodified lines242526272829303132333435363721 unmodified lines596061626364102 unmodified lines1671681691701711721733 unmodified linesimport inspectimport pandas as pdimport wikipedia# (Keep Constants as is)# --- Constants ---DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"14 unmodified linesclass WikipediaAgent:def __init__(self):print("WikipediaAgent initialized.")def __call__(self, question: str) -> str:try:summary = wikipedia.summary(question, sentences=1)return summaryexcept Exception as e:return f"Error: {str(e)}"def run_and_submit_all(agent_name: str, profile: gr.OAuthProfile | None = None):"""Fetches all questions, runs the BasicAgent on them, submits all answers,21 unmodified linesagent = EchoAgent()elif agent_name == "WikipediaAgent":agent = WikipediaAgent()else:return f"Unknown agent selected: {agent_name}", Noneexcept Exception as e:102 unmodified linesgr.LoginButton()agent_dropdown = gr.Dropdown(choices=["BasicAgent", "EchoAgent", "WikipediaAgent"],label="Select Agent",value="BasicAgent")3 unmodified lines4567891014 unmodified lines25262728293031323334353637383940414243444546474849505121 unmodified lines7374757677787980102 unmodified lines1831841851861871881893 unmodified linesimport inspectimport pandas as pdimport wikipediafrom transformers import pipeline# (Keep Constants as is)# --- Constants ---DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"14 unmodified linesclass WikipediaAgent:def __init__(self):wikipedia.set_lang("en")def __call__(self, question: str) -> str:try:# Extract potential keywordquery = question.split(" ")[-1] # naive keyword pickpage = wikipedia.page(query)return wikipedia.summary(page.title, sentences=1)except Exception as e:return "Could not answer"class TransformersAgent:def __init__(self):print("Loading transformers pipeline (flan-t5-base)...")self.model = pipeline("text2text-generation", model="google/flan-t5-base", device=-1) # CPU onlydef __call__(self, question: str) -> str:try:response = self.model(question, max_new_tokens=100)return response[0]['generated_text'].strip()except Exception as e:return f"Error: {str(e)}"def run_and_submit_all(agent_name: str, profile: gr.OAuthProfile | None = None):"""Fetches all questions, runs the BasicAgent on them, submits all answers,21 unmodified linesagent = EchoAgent()elif agent_name == "WikipediaAgent":agent = WikipediaAgent()elif agent_name == "TransformersAgent":agent = TransformersAgent()else:return f"Unknown agent selected: {agent_name}", Noneexcept Exception as e:102 unmodified linesgr.LoginButton()agent_dropdown = gr.Dropdown(choices=["BasicAgent", "EchoAgent", "WikipediaAgent", "TransformersAgent"],label="Select Agent",value="BasicAgent")
app.py+21-5