n094t23g commited on
Commit
2d1e4f3
·
verified ·
1 Parent(s): 8848398

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py CHANGED
@@ -61,4 +61,44 @@ demo = gr.ChatInterface(
61
 
62
 
63
  if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  demo.launch()
 
61
 
62
 
63
  if __name__ == "__main__":
64
+ from sqlalchemy import (
65
+ create_engine,
66
+ MetaData,
67
+ Table,
68
+ Column,
69
+ String,
70
+ Integer,
71
+ Float,
72
+ insert,
73
+ inspect,
74
+ text,
75
+ )
76
+
77
+ engine = create_engine("sqlite:///:memory:")
78
+ metadata_obj = MetaData()
79
+
80
+ def insert_rows_into_table(rows, table, engine=engine):
81
+ for row in rows:
82
+ stmt = insert(table).values(**row)
83
+ with engine.begin() as connection:
84
+ connection.execute(stmt)
85
+
86
+ table_name = "receipts"
87
+ receipts = Table(
88
+ table_name,
89
+ metadata_obj,
90
+ Column("receipt_id", Integer, primary_key=True),
91
+ Column("customer_name", String(16), primary_key=True),
92
+ Column("price", Float),
93
+ Column("tip", Float),
94
+ )
95
+ metadata_obj.create_all(engine)
96
+
97
+ rows = [
98
+ {"receipt_id": 1, "customer_name": "Alan Payne", "price": 12.06, "tip": 1.20},
99
+ {"receipt_id": 2, "customer_name": "Alex Mason", "price": 23.86, "tip": 0.24},
100
+ {"receipt_id": 3, "customer_name": "Woodrow Wilson", "price": 53.43, "tip": 5.43},
101
+ {"receipt_id": 4, "customer_name": "Margaret James", "price": 21.11, "tip": 1.00},
102
+ ]
103
+ insert_rows_into_table(rows, receipts)
104
  demo.launch()