File size: 1,609 Bytes
575b676
 
 
 
 
dd96bb5
575b676
 
5010418
575b676
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5010418
575b676
 
 
5010418
575b676
 
 
 
 
 
db816cc
 
256a5db
db816cc
575b676
256a5db
 
575b676
229b8de
c2e9d49
db816cc
 
575b676
27b47c1
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
44
45
46
47
48
49
50
import gradio as gr
import random
from smolagents import GradioUI, CodeAgent, InferenceClientModel
from smolagents import LiteLLMModel
import os
from PIL import Image

# Import our custom tools from their modules
from tools import evaluate_consumption, evaluate_consumption_example

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()
evaluate_consumption_example = evaluate_consumption_example()

# Create Alfred with all the tools
alfred = CodeAgent(
    tools=[evaluate_consumption, evaluate_consumption_example], 
    model=model,
    additional_authorized_imports=['os'],
    add_base_tools=True,  # Add any additional base tools
    planning_interval=10   
)

demo = gr.Blocks()

with demo:
    hello=gr.Interface(    
    fn=alfred,
    inputs="text",
    outputs="text",
    title="Frugalize it!",
    examples=["What are you capable of ?", "Here is my code, {code}, please give me frugal alternatives"],
    description="Share your Python code with this AI agent! It will track its CO2 emissions using CodeCarbon and recommend greener, frugal AI alternatives.")
    image = gr.Image(Image.open("frugal.jpg"))
    
if __name__ == "__main__":
    demo.launch(mcp_server=True, share=True)