Spaces:
Sleeping
Sleeping
Update app.py
Browse files7 unmodified lines8910111213144 unmodified lines19202122232425262728293078 unmodified lines1091101111121131141151161171187 unmodified linesimport pandas as pdimport toolsfrom smolagents import CodeAgentfrom smolagents.model import HfApiModelfrom typing import TypedDict, List, Dict, Any, Optionalfrom langgraph.graph import StateGraph, START, ENDfrom langchain_core.messages import HumanMessage4 unmodified linesDEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"# --- Models ---def _build_hf_model(model_name: str) -> HfApiModel:"""Build ApiModel across versions that expect repo_id or model_id."""try:return HfApiModel(repo_id=model_name, max_new_tokens=2048, temperature=0.3)except TypeError:return HfApiModel(model_id=model_name, max_new_tokens=2048, temperature=0.3)# Text/math models via smolagents78 unmodified lines"""messages = [HumanMessage(content=prompt)]response = model.invoke(messages)is_searching = response.get("is_searching", False)have_file = response.get("have_file", False)is_math = response.get("is_math", False)have_image = response.get("have_image", False)print(f"Classification result: is_searching={is_searching}, have_file={have_file}, is_math={is_math}, have_image={have_image}")mew_messages = state.get("messages", []) + [{"role": "system", "content": "Classify the question to determine which tools to use."},7 unmodified lines891011121314151617181920214 unmodified lines262728293031323334353637383940414278 unmodified lines1211221231241251261271281291301311321331341351361371381391407 unmodified linesimport pandas as pdimport toolsfrom smolagents import CodeAgenttry:from smolagents import InferenceClientModel as _HFModel # smolagents >= 1.0except ImportError:try:from smolagents.models import HfApiModel as _HFModelexcept ImportError:from smolagents import HfApiModel as _HFModelfrom typing import TypedDict, List, Dict, Any, Optionalfrom langgraph.graph import StateGraph, START, ENDfrom langchain_core.messages import HumanMessage4 unmodified linesDEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"# --- Models ---def _build_hf_model(model_name: str):"""Build a text model across smolagents versions."""for kwargs in ({"model_id": model_name, "max_new_tokens": 2048, "temperature": 0.3},{"repo_id": model_name, "max_new_tokens": 2048, "temperature": 0.3},):try:return _HFModel(**kwargs)except (TypeError, Exception):continueraise RuntimeError(f"Cannot instantiate model {model_name} with available smolagents version")# Text/math models via smolagents78 unmodified lines"""messages = [HumanMessage(content=prompt)]response = model.invoke(messages)# Parse JSON from the model's responseimport json, rematch = re.search(r'\{.*?\}', raw, re.DOTALL)data = {}if match:try:data = json.loads(match.group())except json.JSONDecodeError:passis_searching = bool(data.get("is_searching", False))have_file = bool(data.get("have_file", False))is_math = bool(data.get("is_math", False))have_image = bool(data.get("have_image", False))print(f"Classification result: is_searching={is_searching}, have_file={have_file}, is_math={is_math}, have_image={have_image}")mew_messages = state.get("messages", []) + [{"role": "system", "content": "Classify the question to determine which tools to use."},
app.py+33-11