Spaces:
Sleeping
Sleeping
new db
Browse files
app.py
CHANGED
|
@@ -8,58 +8,94 @@ from tools.final_answer import FinalAnswerTool
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
import sqlite3
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
# Connect to SQLite database. It will be created if it doesn't exist
|
| 15 |
-
conn = sqlite3.connect('employee_database.db')
|
| 16 |
-
cursor = conn.cursor()
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 22 |
-
first_name TEXT NOT NULL,
|
| 23 |
-
last_name TEXT NOT NULL,
|
| 24 |
-
job_title TEXT NOT NULL
|
| 25 |
-
)
|
| 26 |
-
''')
|
| 27 |
-
|
| 28 |
-
# Commit the transaction
|
| 29 |
-
conn.commit()
|
| 30 |
-
|
| 31 |
-
# Sample data for employees
|
| 32 |
-
employees_data = [
|
| 33 |
-
('John', 'Smith', 'Software Engineer'),
|
| 34 |
-
('Sarah', 'Johnson', 'Marketing Manager'),
|
| 35 |
-
('Michael', 'Brown', 'Data Scientist'),
|
| 36 |
-
('Emma', 'Wilson', 'Product Designer'),
|
| 37 |
-
('William', 'Davis', 'DevOps Engineer'),
|
| 38 |
-
('Olivia', 'Miller', 'UX Researcher'),
|
| 39 |
-
('James', 'Wilson', 'Backend Developer'),
|
| 40 |
-
('Jessica', 'Moore', 'Project Manager'),
|
| 41 |
-
('Robert', 'Taylor', 'Frontend Developer'),
|
| 42 |
-
('Lisa', 'Anderson', 'Quality Assurance'),
|
| 43 |
-
('Richard', 'Thomas', 'Technical Writer'),
|
| 44 |
-
('Amy', 'Jackson', 'Business Analyst'),
|
| 45 |
-
('Charles', 'White', 'Database Administrator'),
|
| 46 |
-
('Elizabeth', 'Harris', 'Customer Support'),
|
| 47 |
-
('Thomas', 'Martin', 'Network Engineer'),
|
| 48 |
-
('Jennifer', 'Thompson', 'HR Specialist'),
|
| 49 |
-
('Donald', 'Walker', 'Security Specialist'),
|
| 50 |
-
('Margaret', 'Young', 'Content Manager'),
|
| 51 |
-
('Ronald', 'Allen', 'Sales Representative'),
|
| 52 |
-
('Susan', 'Scott', 'Financial Analyst')
|
| 53 |
-
]
|
| 54 |
|
| 55 |
-
#
|
| 56 |
-
cursor.
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
# Commit the transaction
|
| 62 |
-
conn.commit()
|
| 63 |
|
| 64 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 65 |
@tool
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
import sqlite3
|
| 11 |
+
import random
|
| 12 |
+
|
| 13 |
+
# Sample data for generating employees
|
| 14 |
+
first_names = [
|
| 15 |
+
"John",
|
| 16 |
+
"Emma",
|
| 17 |
+
"Michael",
|
| 18 |
+
"Sarah",
|
| 19 |
+
"William",
|
| 20 |
+
"Olivia",
|
| 21 |
+
"James",
|
| 22 |
+
"Ava",
|
| 23 |
+
"Robert",
|
| 24 |
+
"Isabella",
|
| 25 |
+
]
|
| 26 |
+
last_names = [
|
| 27 |
+
"Smith",
|
| 28 |
+
"Johnson",
|
| 29 |
+
"Williams",
|
| 30 |
+
"Brown",
|
| 31 |
+
"Jones",
|
| 32 |
+
"Davis",
|
| 33 |
+
"Miller",
|
| 34 |
+
"Wilson",
|
| 35 |
+
"Moore",
|
| 36 |
+
"Taylor",
|
| 37 |
+
]
|
| 38 |
+
job_titles = [
|
| 39 |
+
"Software Engineer",
|
| 40 |
+
"Data Analyst",
|
| 41 |
+
"Marketing Manager",
|
| 42 |
+
"Sales Representative",
|
| 43 |
+
"Product Designer",
|
| 44 |
+
]
|
| 45 |
+
departments = ["Engineering", "Finance", "Marketing", "Sales", "Operations"]
|
| 46 |
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
def create_employee_table():
|
| 49 |
+
conn = sqlite3.connect("employee_database.db") # Using in-memory database for demonstration
|
| 50 |
+
cursor = conn.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
# Create employees table
|
| 53 |
+
cursor.execute(
|
| 54 |
+
"""
|
| 55 |
+
CREATE TABLE IF NOT EXISTS employees (
|
| 56 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 57 |
+
first_name TEXT NOT NULL,
|
| 58 |
+
last_name TEXT NOT NULL,
|
| 59 |
+
job_title TEXT NOT NULL,
|
| 60 |
+
department_name TEXT NOT NULL,
|
| 61 |
+
salary REAL NOT NULL
|
| 62 |
+
)
|
| 63 |
+
"""
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
# Generate and insert sample data
|
| 67 |
+
for _ in range(30):
|
| 68 |
+
employee = {
|
| 69 |
+
"first_name": random.choice(first_names),
|
| 70 |
+
"last_name": random.choice(last_names),
|
| 71 |
+
"job_title": random.choice(job_titles),
|
| 72 |
+
"department_name": random.choice(departments),
|
| 73 |
+
"salary": round(random.uniform(40000, 120000), 2),
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
cursor.execute(
|
| 77 |
+
"""
|
| 78 |
+
INSERT INTO employees
|
| 79 |
+
(first_name, last_name, job_title, department_name, salary)
|
| 80 |
+
VALUES (?, ?, ?, ?, ?)
|
| 81 |
+
""",
|
| 82 |
+
(
|
| 83 |
+
employee["first_name"],
|
| 84 |
+
employee["last_name"],
|
| 85 |
+
employee["job_title"],
|
| 86 |
+
employee["department_name"],
|
| 87 |
+
employee["salary"],
|
| 88 |
+
),
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
conn.commit()
|
| 92 |
+
|
| 93 |
+
conn.close()
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
# Create and populate the database
|
| 97 |
+
create_employee_table()
|
| 98 |
|
|
|
|
|
|
|
| 99 |
|
| 100 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 101 |
@tool
|