Spaces:
Runtime error
Runtime error
Update app.py
Browse files6 unmodified lines789101112131415161718192021226 unmodified linesfrom Gradio_UI import GradioUI# Below is an example of a tool that does nothing. Amaze us with your creativity !@tooldef my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type#Keep this format for the description / args / args description but feel free to modify the tool"""A tool that does nothing yetArgs:arg1: the first argumentarg2: the second argument"""return "What magic will you build ?"@tooldef get_current_time_in_timezone(timezone: str) -> str:6 unmodified lines78910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273746 unmodified linesfrom Gradio_UI import GradioUIimport mathimport randomfrom typing import Literal# Below is an example of a tool that does nothing. Amaze us with your creativity !import mathimport randomfrom typing import Literalfrom your_agent_framework import tool # adjust import to your AI agent framework@tooldef get_approximate_integral(expr: str,a: float,b: float,method: Literal["auto", "simpson", "montecarlo"] = "auto",samples: int = 1000) -> str:"""Approximate the definite integral of a function over [a, b].Args:expr: A Python expression in variable `x`, e.g. "math.sin(x) + x**2".a: Lower limit of integration.b: Upper limit of integration.method: Which algorithm to use:- "simpson": composite Simpson’s rule- "montecarlo": randomized Monte Carlo- "auto" (default): picks Simpson for smoothness, Monte Carlo otherwise.samples: Number of panels (for Simpson) or random points (for Monte Carlo)."""# Safely compile the expressioncode = compile(expr, "<string>", "eval")def f(x):return eval(code, {"__builtins__": {}}, {"x": x, "math": math})# Auto‑choose method by sampling curvatureif method == "auto":mid = (a + b) / 2# estimate curvature via second finite differencef0, f1, f2 = f(a), f(mid), f(b)curvature = abs((f0 - 2*f1 + f2) / ((b - a)/2)**2)method = "montecarlo" if curvature > 1e3 else "simpson"if method == "simpson":n = samples if samples % 2 == 0 else samples + 1h = (b - a) / ntotal = f(a) + f(b)for i in range(1, n):weight = 4 if i % 2 else 2total += weight * f(a + i * h)result = total * h / 3return f'{{"value": {result}, "method": "simpson", "panels": {n}}}'# Monte Carlo fallbackinside = 0.0for _ in range(samples):x = random.uniform(a, b)inside += f(x)result = (b - a) * inside / samplesreturn f'{{"value": {result}, "method": "montecarlo", "samples": {samples}}}'@tooldef get_current_time_in_timezone(timezone: str) -> str:
app.py+58-6