Spaces:
Sleeping
Sleeping
File size: 4,020 Bytes
9b5b26a c19d193 6aae614 8fe992b 9b5b26a 6b1c2e6 3533c1a 6b1c2e6 3533c1a 6b1c2e6 3533c1a 6b1c2e6 3533c1a 6b1c2e6 3533c1a 6b1c2e6 3533c1a 9b5b26a 6b1c2e6 9b5b26a 6b1c2e6 9b5b26a 6b1c2e6 9b5b26a ca455d7 ee9d643 6bad9e1 ee9d643 6bad9e1 ee9d643 8c01ffb 6aae614 ae7a494 e121372 bf6d34c 29ec968 fe328e0 13d500a 8c01ffb 9b5b26a 8c01ffb 861422e 9b5b26a 8c01ffb 8fe992b 6b1c2e6 8c01ffb 861422e 8fe992b 9b5b26a 8c01ffb |
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
import datetime
import requests
import pytz
import yaml
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI
import sqlite3
import random
# Sample data for generating employees
first_names = [
"John",
"Emma",
"Michael",
"Sarah",
"William",
"Olivia",
"James",
"Ava",
"Robert",
"Isabella",
]
last_names = [
"Smith",
"Johnson",
"Williams",
"Brown",
"Jones",
"Davis",
"Miller",
"Wilson",
"Moore",
"Taylor",
]
job_titles = [
"Software Engineer",
"Data Analyst",
"Marketing Manager",
"Sales Representative",
"Product Designer",
]
departments = ["Engineering", "Finance", "Marketing", "Sales", "Operations"]
def create_employee_table():
conn = sqlite3.connect("employee_database.db") # Using in-memory database for demonstration
cursor = conn.cursor()
# Create employees table
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS employees (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
job_title TEXT NOT NULL,
department_name TEXT NOT NULL,
salary REAL NOT NULL
)
"""
)
# Generate and insert sample data
for _ in range(30):
employee = {
"first_name": random.choice(first_names),
"last_name": random.choice(last_names),
"job_title": random.choice(job_titles),
"department_name": random.choice(departments),
"salary": round(random.uniform(40000, 120000), 2),
}
cursor.execute(
"""
INSERT INTO employees
(first_name, last_name, job_title, department_name, salary)
VALUES (?, ?, ?, ?, ?)
""",
(
employee["first_name"],
employee["last_name"],
employee["job_title"],
employee["department_name"],
employee["salary"],
),
)
conn.commit()
conn.close()
# Create and populate the database
create_employee_table()
# Below is an example of a tool that does nothing. Amaze us with your creativity !
@tool
def get_employee_job_title(first_name:str, last_name:str)-> str: #it's import to specify the return type
"""A tool that allows to do a sqlite sql query based on first_name and last_name
Args:
first_name: the first argument
last_name: the second argument
"""
conn = sqlite3.connect('employee_database.db')
cursor = conn.cursor()
cursor.execute(f"SELECT job_title FROM employees WHERE first_name='{first_name}' AND last_name='{last_name}'")
rows = cursor.fetchall()
if len(rows) > 1:
return "Many employees with that name"
elif len(rows) == 0:
return "No employee with that name"
else:
row = rows[0][0]
return row
final_answer = FinalAnswerTool()
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
model = HfApiModel(
max_tokens=2096,
temperature=0.5,
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
custom_role_conversions=None,
)
# Import tool from Hub
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
with open("prompts.yaml", 'r') as stream:
prompt_templates = yaml.safe_load(stream)
agent = CodeAgent(
model=model,
tools=[final_answer, get_employee_job_title], ## add your tools here (don't remove final answer)
max_steps=6,
verbosity_level=1,
grammar=None,
planning_interval=None,
name=None,
description=None,
prompt_templates=prompt_templates
)
GradioUI(agent).launch() |