| | |
| | from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel |
| | import gradio as gr |
| | import os |
| |
|
| | |
| | hf_token = os.getenv("HF_TOKEN") |
| | if not hf_token: |
| | raise ValueError("HF_TOKEN not set in environment variables") |
| |
|
| | |
| | model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct", token=hf_token) |
| |
|
| | |
| | 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)}" |
| |
|
| | |
| | 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) |