Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,27 +4,28 @@ import psycopg2
|
|
4 |
import pandas as pd
|
5 |
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
@st.experimental_memo(ttl=600)
|
21 |
-
def run_query(query):
|
22 |
-
with conn.cursor() as cur:
|
23 |
-
cur.execute(query)
|
24 |
-
return cur.fetchall()
|
25 |
|
26 |
-
|
|
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
st.write(f"{row[0]} has a :{row[1]}:")
|
|
|
4 |
import pandas as pd
|
5 |
|
6 |
|
7 |
+
# Function to get data from the TimescaleDB
|
8 |
+
def get_data():
|
9 |
+
# Connect to your PostgreSQL database
|
10 |
+
conn = psycopg2.connect(
|
11 |
+
dbname="postgres",
|
12 |
+
user="postgres",
|
13 |
+
password="database",
|
14 |
+
host="localhost",
|
15 |
+
port="5432"
|
16 |
+
)
|
17 |
+
cur = conn.cursor()
|
18 |
+
cur.execute("SELECT BRAND, MODEL ,LAUNCH_YR FROM CARS LIMIT 100;")
|
19 |
+
data = cur.fetchall()
|
20 |
+
cur.close()
|
21 |
+
conn.close()
|
22 |
+
return data
|
23 |
|
24 |
+
# Streamlit application
|
25 |
+
st.title('Cars-Data')
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
+
data = get_data()
|
28 |
+
df = pd.DataFrame(data, columns=['BRAND', 'MODEL','LAUNCH_YR'])
|
29 |
|
30 |
+
st.write("## Latest 10 Records from cars")
|
31 |
+
st.dataframe(df)
|
|