Spaces:
Sleeping
Sleeping
Commit
·
d1975ef
1
Parent(s):
4b8ba20
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,10 @@ import sqlite3
|
|
| 4 |
import numpy as np
|
| 5 |
import pandas as pd
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
## Function to read SQL data
|
| 9 |
def read_sql_query(sql, db):
|
|
@@ -35,10 +39,28 @@ if i_pwd=='password':
|
|
| 35 |
|
| 36 |
create_table_statement= "CREATE TABLE car_sales (Manufacturer text, Model text, Sales_in_thousands float, __year_resale_value float, Vehicle_type text, Price_in_thousands float, Engine_size float, Horsepower float, Wheelbase float, Width float, Length float, Curb_weight float, Fuel_capacity float, Fuel_efficiency float, Latest_Launch text, Power_perf_factor float)"
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
# Step 1: User input
|
| 39 |
with st.chat_message(name= 'assistant'):
|
| 40 |
-
st.
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
# Step 2: Backend processing on Enter
|
| 44 |
if user_query:
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
+
#initialize chat history
|
| 8 |
+
if messages not in st.session_state():
|
| 9 |
+
st.session_state.messages=[]
|
| 10 |
+
|
| 11 |
|
| 12 |
## Function to read SQL data
|
| 13 |
def read_sql_query(sql, db):
|
|
|
|
| 39 |
|
| 40 |
create_table_statement= "CREATE TABLE car_sales (Manufacturer text, Model text, Sales_in_thousands float, __year_resale_value float, Vehicle_type text, Price_in_thousands float, Engine_size float, Horsepower float, Wheelbase float, Width float, Length float, Curb_weight float, Fuel_capacity float, Fuel_efficiency float, Latest_Launch text, Power_perf_factor float)"
|
| 41 |
|
| 42 |
+
# display chat messages from history
|
| 43 |
+
for message in st.session_state.messages:
|
| 44 |
+
with st.chat_message(message['role']):
|
| 45 |
+
st.markdown(message['content'])
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
# Step 1: User input
|
| 50 |
with st.chat_message(name= 'assistant'):
|
| 51 |
+
st.markdown('Ask question and press Enter')
|
| 52 |
+
st.session_state.messages.append({"role":"assistant", "content": 'Ask question and press Enter' })
|
| 53 |
+
|
| 54 |
+
user_query= st.chat_input('')
|
| 55 |
+
if user_query:
|
| 56 |
+
with st.chat_message('user'):
|
| 57 |
+
st.markdown(user_query)
|
| 58 |
+
|
| 59 |
+
st.session_state.messages.append({"role":"user", "content": user_query })
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
#user_query = st.text_input("")
|
| 64 |
|
| 65 |
# Step 2: Backend processing on Enter
|
| 66 |
if user_query:
|