pandoucha's picture
Update app.py
3fbc363 verified
raw
history blame
1.2 kB
# app.py
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
import gradio as gr
import os
# Load token from environment variable
hf_token = os.getenv("HF_TOKEN")
if not hf_token:
raise ValueError("HF_TOKEN not set in environment variables")
# Initialize the model with explicit model ID and token
model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct", token=hf_token)
# Initialize the agent
agent = CodeAgent(
tools=[DuckDuckGoSearchTool()],
model=model,
add_base_tools=True
)
def find_lowest_price(product):
task = f"Search for the product '{product}' on Tunisian websites (domain .tn) and find the lowest price in TND."
try:
result = agent.run(task)
return result
except Exception as e:
return f"Error: {str(e)}"
# Gradio interface
interface = gr.Interface(
fn=find_lowest_price,
inputs=gr.Textbox(label="Enter the product to search for", placeholder="e.g., olive oil"),
outputs=gr.Textbox(label="Lowest Price Result"),
title="Tunisian Product Price Finder",
description="Enter a product name to find its lowest price on Tunisian websites."
)
interface.launch(server_name="0.0.0.0", server_port=7860)