Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import random | |
| from smolagents import GradioUI, CodeAgent, InferenceClientModel | |
| from smolagents import LiteLLMModel | |
| import os | |
| # Import our custom tools from their modules | |
| from tools import evaluate_consumption | |
| HF_TOKEN = os.environ.get("HF_TOKEN") | |
| API_KEY = os.environ.get("API_KEY") | |
| # Initialize the Hugging Face model | |
| model = LiteLLMModel( | |
| model_id="anthropic/claude-3-5-sonnet-latest", | |
| temperature=0.2, | |
| api_key=os.environ["API_KEY"] | |
| ) | |
| #model = InferenceClientModel("deepseek-ai/DeepSeek-R1",max_tokens=500, token=HF_TOKEN) | |
| headers = { | |
| "Authorization": f"Bearer {HF_TOKEN}" | |
| } | |
| # Initialize the weather tool | |
| evaluate_consumption = evaluate_consumption() | |
| # Create Alfred with all the tools | |
| alfred = CodeAgent( | |
| tools=[evaluate_consumption], | |
| model=model, | |
| additional_authorized_imports=['os'], | |
| add_base_tools=True, # Add any additional base tools | |
| planning_interval=10 | |
| ) | |
| demo=gr.Interface( | |
| fn=alfred, | |
| inputs="text", | |
| outputs="text", | |
| title="Frugalize it!", | |
| description="Share your Python code with this AI agent! It will track its CO2 emissions using CodeCarbon and recommend greener, frugal AI alternatives.") | |
| if __name__ == "__main__": | |
| demo.launch(mcp_server=True, share=True) |