Frugal_AI_Agent / app.py
CindyDelage's picture
Update app.py
db816cc verified
raw
history blame
1.61 kB
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)