themissingCRAM commited on
Commit
b1ab131
·
1 Parent(s): f1d9f2e
Files changed (4) hide show
  1. Constants.py +169 -0
  2. __pycache__/Constants.cpython-311.pyc +0 -0
  3. app.py +28 -166
  4. sqlite3.sqlite +0 -0
Constants.py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+ '''
3
+ ai generated data
4
+ '''
5
+
6
+ bakery_orders_data = [
7
+ {
8
+ "order_id": 1,
9
+ "ingredient_name": "Flour",
10
+ "supplier_name": "Supplier A",
11
+ "quantity_ordered": 50.00,
12
+ "unit": "kg",
13
+ "price_per_unit": 1.20,
14
+ "total_cost": 60.00, # This can be calculated as quantity_ordered * price_per_unit
15
+ "order_date": datetime.strptime("2023-10-01 10:00:00","%Y-%m-%d %H:%M:%S" )
16
+
17
+ },
18
+ {
19
+ "order_id": 2,
20
+ "ingredient_name": "Sugar",
21
+ "supplier_name": "Supplier B",
22
+ "quantity_ordered": 20.00,
23
+ "unit": "kg",
24
+ "price_per_unit": 0.80,
25
+ "total_cost": 16.00,
26
+ "order_date": datetime.strptime( "2023-10-02 11:30:00","%Y-%m-%d %H:%M:%S" )
27
+ },
28
+ {
29
+ "order_id": 3,
30
+ "ingredient_name": "Butter",
31
+ "supplier_name": "Supplier C",
32
+ "quantity_ordered": 10.00,
33
+ "unit": "kg",
34
+ "price_per_unit": 3.00,
35
+ "total_cost": 30.00,
36
+ "order_date": datetime.strptime( "2023-10-03 09:15:00","%Y-%m-%d %H:%M:%S" )
37
+ },
38
+ {
39
+ "order_id": 4,
40
+ "ingredient_name": "Eggs",
41
+ "supplier_name": "Supplier D",
42
+ "quantity_ordered": 5.00,
43
+ "unit": "dozen",
44
+ "price_per_unit": 2.50,
45
+ "total_cost": 12.50,
46
+ "order_date": datetime.strptime( "2023-10-04 14:45:00","%Y-%m-%d %H:%M:%S" )
47
+ },
48
+ {
49
+ "order_id": 5,
50
+ "ingredient_name": "Baking Powder",
51
+ "supplier_name": "Supplier E",
52
+ "quantity_ordered": 2.00,
53
+ "unit": "kg",
54
+ "price_per_unit": 4.00,
55
+ "total_cost": 8.00,
56
+ "order_date": datetime.strptime( "2023-10-05 08:30:00","%Y-%m-%d %H:%M:%S" )
57
+ }
58
+ ]
59
+
60
+ baking_recipes = [
61
+ {
62
+ "name": "Lemon Blueberry Muffins",
63
+ "ingredients": [
64
+ "1 1/2 cups all-purpose flour",
65
+ "1/2 cup sugar",
66
+ "2 tsp baking powder",
67
+ "1/2 tsp salt",
68
+ "1/2 cup milk",
69
+ "1/3 cup vegetable oil",
70
+ "1 large egg",
71
+ "1 tsp vanilla extract",
72
+ "1 cup fresh blueberries",
73
+ "Zest of 1 lemon",
74
+ "Juice of 1 lemon"
75
+ ],
76
+ "instructions": [
77
+ "Preheat the oven to 375°F (190°C) and line a muffin tin with paper liners.",
78
+ "In a bowl, mix flour, sugar, baking powder, and salt.",
79
+ "In another bowl, whisk together milk, oil, egg, vanilla, lemon zest, and lemon juice.",
80
+ "Combine wet and dry ingredients until just mixed, then fold in blueberries.",
81
+ "Spoon the batter into the muffin tin and bake for 18-20 minutes."
82
+ ]
83
+ },
84
+ {
85
+ "name": "Chocolate Chip Cookies",
86
+ "ingredients": [
87
+ "1 cup unsalted butter, softened",
88
+ "3/4 cup sugar",
89
+ "3/4 cup brown sugar",
90
+ "1 tsp vanilla extract",
91
+ "2 large eggs",
92
+ "2 1/4 cups all-purpose flour",
93
+ "1 tsp baking soda",
94
+ "1/2 tsp salt",
95
+ "2 cups chocolate chips"
96
+ ],
97
+ "instructions": [
98
+ "Preheat the oven to 350°F (175°C).",
99
+ "In a bowl, cream together butter, sugar, and brown sugar until smooth.",
100
+ "Beat in vanilla and eggs one at a time.",
101
+ "In another bowl, combine flour, baking soda, and salt.",
102
+ "Gradually blend dry ingredients into the wet mixture.",
103
+ "Stir in chocolate chips.",
104
+ "Drop by rounded tablespoons onto ungreased baking sheets and bake for 9-11 minutes."
105
+ ]
106
+ },
107
+ {
108
+ "name": "Banana Bread",
109
+ "ingredients": [
110
+ "3 ripe bananas, mashed",
111
+ "1/3 cup melted butter",
112
+ "1 tsp baking soda",
113
+ "Pinch of salt",
114
+ "3/4 cup sugar",
115
+ "1 large egg, beaten",
116
+ "1 tsp vanilla extract",
117
+ "1 1/2 cups all-purpose flour"
118
+ ],
119
+ "instructions": [
120
+ "Preheat the oven to 350°F (175°C) and grease a 4x8 inch loaf pan.",
121
+ "In a mixing bowl, mix the mashed bananas with the melted butter.",
122
+ "Stir in baking soda and salt.",
123
+ "Add sugar, egg, and vanilla, and mix well.",
124
+ "Finally, mix in the flour until just incorporated.",
125
+ "Pour the batter into the prepared loaf pan and bake for 60-65 minutes."
126
+ ]
127
+ },
128
+ {
129
+ "name": "Cinnamon Rolls",
130
+ "ingredients": [
131
+ "4 cups all-purpose flour",
132
+ "1/4 cup sugar",
133
+ "1 packet (2 1/4 tsp) active dry yeast",
134
+ "1 tsp salt",
135
+ "1 cup milk, warmed",
136
+ "1/4 cup unsalted butter, melted",
137
+ "2 large eggs",
138
+ "1/2 cup brown sugar",
139
+ "2 tbsp cinnamon",
140
+ "1/4 cup unsalted butter, softened (for filling)",
141
+ "1 cup powdered sugar (for icing)",
142
+ "2-3 tbsp milk (for icing)"
143
+ ],
144
+ "instructions": [
145
+ "In a bowl, combine flour, sugar, yeast, and salt.",
146
+ "In another bowl, mix warm milk, melted butter, and eggs.",
147
+ "Combine wet and dry ingredients and knead until smooth.",
148
+ "Let the dough rise for 1 hour.",
149
+ "Roll out the dough, spread softened butter, and sprinkle with brown sugar and cinnamon.",
150
+ "Roll up the dough and cut into slices.",
151
+ "Place in a greased baking dish and let rise for another 30 minutes.",
152
+ "Bake at 350°F (175°C) for 25-30 minutes.",
153
+ "Mix powdered sugar and milk to make icing and drizzle over warm rolls."
154
+ ]
155
+ },
156
+ {
157
+ "name": "Pumpkin Pie",
158
+ "ingredients": [
159
+ "1 (9-inch) pie crust",
160
+ "1 can (15 oz) pumpkin puree",
161
+ "3/4 cup sugar",
162
+ "1/2 tsp salt",
163
+ "1 tsp ground cinnamon",
164
+ "1/2 tsp ground ginger",
165
+ "1/4 tsp ground nutmeg",
166
+ "1/4 tsp ground cloves",
167
+ "3 large eggs",
168
+ "1 can (12 oz) evaporated milk"
169
+ ]},]
__pycache__/Constants.cpython-311.pyc ADDED
Binary file (4.37 kB). View file
 
app.py CHANGED
@@ -13,9 +13,9 @@ from sqlalchemy import (
13
  Integer,
14
  Float,
15
  insert,
16
- text,
17
  )
18
-
19
  import gradio as gr
20
  import os
21
  from smolagents import Tool, CodeAgent, HfApiModel, stream_to_gradio
@@ -24,123 +24,12 @@ from dotenv import load_dotenv
24
  from langchain.docstore.document import Document
25
  import chromadb
26
  from chromadb.utils import embedding_functions
27
-
28
  load_dotenv()
29
  #sample questions
30
  # What is the average each customer paid?
31
  # Create a sql statement and invoke your sql_engine tool
32
 
33
- baking_recipes = [
34
- {
35
- "name": "Lemon Blueberry Muffins",
36
- "ingredients": [
37
- "1 1/2 cups all-purpose flour",
38
- "1/2 cup sugar",
39
- "2 tsp baking powder",
40
- "1/2 tsp salt",
41
- "1/2 cup milk",
42
- "1/3 cup vegetable oil",
43
- "1 large egg",
44
- "1 tsp vanilla extract",
45
- "1 cup fresh blueberries",
46
- "Zest of 1 lemon",
47
- "Juice of 1 lemon"
48
- ],
49
- "instructions": [
50
- "Preheat the oven to 375°F (190°C) and line a muffin tin with paper liners.",
51
- "In a bowl, mix flour, sugar, baking powder, and salt.",
52
- "In another bowl, whisk together milk, oil, egg, vanilla, lemon zest, and lemon juice.",
53
- "Combine wet and dry ingredients until just mixed, then fold in blueberries.",
54
- "Spoon the batter into the muffin tin and bake for 18-20 minutes."
55
- ]
56
- },
57
- {
58
- "name": "Chocolate Chip Cookies",
59
- "ingredients": [
60
- "1 cup unsalted butter, softened",
61
- "3/4 cup sugar",
62
- "3/4 cup brown sugar",
63
- "1 tsp vanilla extract",
64
- "2 large eggs",
65
- "2 1/4 cups all-purpose flour",
66
- "1 tsp baking soda",
67
- "1/2 tsp salt",
68
- "2 cups chocolate chips"
69
- ],
70
- "instructions": [
71
- "Preheat the oven to 350°F (175°C).",
72
- "In a bowl, cream together butter, sugar, and brown sugar until smooth.",
73
- "Beat in vanilla and eggs one at a time.",
74
- "In another bowl, combine flour, baking soda, and salt.",
75
- "Gradually blend dry ingredients into the wet mixture.",
76
- "Stir in chocolate chips.",
77
- "Drop by rounded tablespoons onto ungreased baking sheets and bake for 9-11 minutes."
78
- ]
79
- },
80
- {
81
- "name": "Banana Bread",
82
- "ingredients": [
83
- "3 ripe bananas, mashed",
84
- "1/3 cup melted butter",
85
- "1 tsp baking soda",
86
- "Pinch of salt",
87
- "3/4 cup sugar",
88
- "1 large egg, beaten",
89
- "1 tsp vanilla extract",
90
- "1 1/2 cups all-purpose flour"
91
- ],
92
- "instructions": [
93
- "Preheat the oven to 350°F (175°C) and grease a 4x8 inch loaf pan.",
94
- "In a mixing bowl, mix the mashed bananas with the melted butter.",
95
- "Stir in baking soda and salt.",
96
- "Add sugar, egg, and vanilla, and mix well.",
97
- "Finally, mix in the flour until just incorporated.",
98
- "Pour the batter into the prepared loaf pan and bake for 60-65 minutes."
99
- ]
100
- },
101
- {
102
- "name": "Cinnamon Rolls",
103
- "ingredients": [
104
- "4 cups all-purpose flour",
105
- "1/4 cup sugar",
106
- "1 packet (2 1/4 tsp) active dry yeast",
107
- "1 tsp salt",
108
- "1 cup milk, warmed",
109
- "1/4 cup unsalted butter, melted",
110
- "2 large eggs",
111
- "1/2 cup brown sugar",
112
- "2 tbsp cinnamon",
113
- "1/4 cup unsalted butter, softened (for filling)",
114
- "1 cup powdered sugar (for icing)",
115
- "2-3 tbsp milk (for icing)"
116
- ],
117
- "instructions": [
118
- "In a bowl, combine flour, sugar, yeast, and salt.",
119
- "In another bowl, mix warm milk, melted butter, and eggs.",
120
- "Combine wet and dry ingredients and knead until smooth.",
121
- "Let the dough rise for 1 hour.",
122
- "Roll out the dough, spread softened butter, and sprinkle with brown sugar and cinnamon.",
123
- "Roll up the dough and cut into slices.",
124
- "Place in a greased baking dish and let rise for another 30 minutes.",
125
- "Bake at 350°F (175°C) for 25-30 minutes.",
126
- "Mix powdered sugar and milk to make icing and drizzle over warm rolls."
127
- ]
128
- },
129
- {
130
- "name": "Pumpkin Pie",
131
- "ingredients": [
132
- "1 (9-inch) pie crust",
133
- "1 can (15 oz) pumpkin puree",
134
- "3/4 cup sugar",
135
- "1/2 tsp salt",
136
- "1 tsp ground cinnamon",
137
- "1/2 tsp ground ginger",
138
- "1/4 tsp ground nutmeg",
139
- "1/4 tsp ground cloves",
140
- "3 large eggs",
141
- "1 can (12 oz) evaporated milk"
142
- ]},]
143
-
144
 
145
  @spaces.GPU
146
  def dummy():
@@ -243,57 +132,40 @@ def init_db(_engine):
243
  with _engine.begin() as connection:
244
  connection.execute(stmt)
245
 
246
- table_name = "receipts"
247
- receipts = Table(
248
- table_name,
249
- metadata_obj,
250
- Column("receipt_id", Integer, primary_key=True),
251
- Column("customer_name", String(16), primary_key=True),
252
- Column("price", Float),
253
- Column("tip", Float),
254
- )
255
- metadata_obj.create_all(_engine)
256
-
257
- rows = [
258
- {"receipt_id": 1, "customer_name": "Alan Payne", "price": 12.06, "tip": 1.20},
259
- {"receipt_id": 2, "customer_name": "Alex Mason", "price": 23.86, "tip": 0.24},
260
- {
261
- "receipt_id": 3,
262
- "customer_name": "Woodrow Wilson",
263
- "price": 53.43,
264
- "tip": 5.43,
265
- },
266
- {
267
- "receipt_id": 4,
268
- "customer_name": "Margaret James",
269
- "price": 21.11,
270
- "tip": 1.00,
271
- },
272
- ]
273
- insert_rows_into_table(rows, receipts)
274
-
275
- table_name = "waiters"
276
- waiters = Table(
277
- table_name,
278
  metadata_obj,
279
- Column("receipt_id", Integer, primary_key=True),
280
- Column("waiter_name", String(16), primary_key=True),
 
 
 
 
 
 
 
 
281
  )
282
  metadata_obj.create_all(_engine)
 
283
 
284
- rows = [
285
- {"receipt_id": 1, "waiter_name": "Corey Johnson"},
286
- {"receipt_id": 2, "waiter_name": "Michael Watts"},
287
- {"receipt_id": 3, "waiter_name": "Michael Watts"},
288
- {"receipt_id": 4, "waiter_name": "Margaret James"},
289
- ]
290
- insert_rows_into_table(rows, waiters)
291
  return _engine
292
 
293
 
294
  if __name__ == "__main__":
295
- engine = create_engine("sqlite:///:localhost:")
296
  engine = init_db(engine)
 
 
 
 
 
 
 
 
 
 
 
297
  model = HfApiModel(
298
  model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
299
  # model_id="meta-llama/Meta-Llama-3.1-8B-Instruct",
@@ -306,16 +178,6 @@ if __name__ == "__main__":
306
  max_steps=10,
307
  verbosity_level=1,
308
  )
309
- source_docs = HuggingFaceDatasetLoader("MuskumPillerum/General-Knowledge", "Answer").load()[:100]
310
- text_splitter = RecursiveCharacterTextSplitter(
311
- chunk_size=500,
312
- chunk_overlap=50,
313
- add_start_index=True,
314
- strip_whitespace=True,
315
- separators=["\n\n", "\n", ".", " ", ""],
316
- )
317
- docs_processed = text_splitter.split_documents(source_docs)
318
- retriever_tool = RetrieverTool(docs_processed)
319
 
320
 
321
  retriever_agent = CodeAgent(
 
13
  Integer,
14
  Float,
15
  insert,
16
+ text, Numeric, DateTime,func
17
  )
18
+ import datetime
19
  import gradio as gr
20
  import os
21
  from smolagents import Tool, CodeAgent, HfApiModel, stream_to_gradio
 
24
  from langchain.docstore.document import Document
25
  import chromadb
26
  from chromadb.utils import embedding_functions
27
+ from Constants import bakery_orders_data,baking_recipes
28
  load_dotenv()
29
  #sample questions
30
  # What is the average each customer paid?
31
  # Create a sql statement and invoke your sql_engine tool
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  @spaces.GPU
35
  def dummy():
 
132
  with _engine.begin() as connection:
133
  connection.execute(stmt)
134
 
135
+ baking_ingredients_order = Table(
136
+ 'baking_ingredients_order', # Table name
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  metadata_obj,
138
+ Column("order_id", Integer, primary_key=True, autoincrement=True),
139
+ Column("ingredient_name", String(100), nullable=False),
140
+ Column("supplier_name", String(100), nullable=False),
141
+ Column("quantity_ordered", Numeric(10, 2), nullable=False),
142
+ Column("unit", String(50), nullable=False),
143
+ Column("price_per_unit", Numeric(10, 2), nullable=False),
144
+ Column("total_cost", Numeric(10, 2),
145
+ default=func.expr('quantity_ordered * price_per_unit'),
146
+ nullable=False),
147
+ Column("order_date", DateTime, default=datetime.datetime.now())
148
  )
149
  metadata_obj.create_all(_engine)
150
+ insert_rows_into_table(bakery_orders_data, baking_ingredients_order)
151
 
 
 
 
 
 
 
 
152
  return _engine
153
 
154
 
155
  if __name__ == "__main__":
156
+ engine = create_engine("sqlite:///sqlite3.sqlite")
157
  engine = init_db(engine)
158
+ source_docs = HuggingFaceDatasetLoader("MuskumPillerum/General-Knowledge", "Answer").load()[:100]
159
+ text_splitter = RecursiveCharacterTextSplitter(
160
+ chunk_size=500,
161
+ chunk_overlap=50,
162
+ add_start_index=True,
163
+ strip_whitespace=True,
164
+ separators=["\n\n", "\n", ".", " ", ""],
165
+ )
166
+ docs_processed = text_splitter.split_documents(source_docs)
167
+ retriever_tool = RetrieverTool(docs_processed)
168
+
169
  model = HfApiModel(
170
  model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
171
  # model_id="meta-llama/Meta-Llama-3.1-8B-Instruct",
 
178
  max_steps=10,
179
  verbosity_level=1,
180
  )
 
 
 
 
 
 
 
 
 
 
181
 
182
 
183
  retriever_agent = CodeAgent(
sqlite3.sqlite ADDED
Binary file (8.19 kB). View file