File size: 1,269 Bytes
575b676
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)