-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
101 lines (86 loc) · 3.76 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import streamlit as st
import psycopg2
# Connect to the PostgreSQL database using pgAdmin credentials
conn = psycopg2.connect(
host="localhost",
database="imdb",
user="postgres",
password="1308"
)
# Define a function to run SQL queries
def run_query(query):
cursor = conn.cursor()
cursor.execute(query)
result = cursor.fetchall()
return result
# Define the Streamlit app
def main():
st.set_page_config(page_title="FilmVerse",
page_icon=":smiley:", layout="wide")
st.markdown("<h1 style='color: black; font-weight: bold;'>FilmVerse</h1>",
unsafe_allow_html=True)
# Set the page configuration
# Add a CSS style to the app
st.markdown(
"""
<style>
.stApp {
background-image: url('https://drive.google.com/uc?id=1R4rZggPGWlSUfUHFAMdezL5sXh1VnY7G');
background-repeat: no-repeat;
background-size: cover;
}
.stApp::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(255, 255, 255, 0.5);
}
body {
color: black;
font-weight: bold;
}
</style>
""",
unsafe_allow_html=True
)
# Define the dropdown options and their corresponding queries
queries = {
"Top 10 Comedy Movies": "SELECT DISTINCT primary_title, start_year, average_rating FROM basics JOIN ratings ON basics.tconst = ratings.tconst WHERE genres = 'Comedy' and average_rating >= 6.0 ORDER BY average_rating DESC LIMIT 10;",
"Top 10 Short Movies": "SELECT primary_title, start_year, average_rating FROM basics JOIN ratings ON basics.tconst = ratings.tconst WHERE genres = 'Short' ORDER BY average_rating DESC LIMIT 10;",
"Top 10 Documentary": "SELECT primary_title, start_year, average_rating FROM basics JOIN ratings ON basics.tconst = ratings.tconst WHERE genres = 'Documentary' ORDER BY average_rating DESC LIMIT 10;",
"Top 10 Drama Movies": "SELECT primary_title, start_year, average_rating FROM basics JOIN ratings ON basics.tconst = ratings.tconst WHERE genres = 'Drama' ORDER BY average_rating DESC LIMIT 10;",
}
# Add a dropdown to select the SQL query
query_option = st.selectbox("Select an SQL query:", list(queries.keys()))
# Get the selected query and run it when the button is clicked
if st.button("Run Query", key="run_query_1"):
query = queries[query_option]
result = run_query(query)
print(result)
# Create a table with black text color
table_html = "<table style='color:black'><thead><tr>"
for row in result:
table_html += "<tr>"
for col in row:
table_html += f"<td>{col}</td>"
table_html += "</tr>"
table_html += "</tbody></table>"
# Display the table
st.markdown(table_html, unsafe_allow_html=True)
# Show a table of movies
st.markdown("<h3 style='color: black; font-weight: bold;'>Top 10 Movies</h1>",
unsafe_allow_html=True)
query = "SELECT primary_title, start_year, average_rating FROM basics JOIN ratings ON basics.tconst = ratings.tconst WHERE average_rating >= 7.0 ORDER BY average_rating DESC LIMIT 10;"
result = run_query(query)
# Create a table with black text color
table_html = "<table style='color:black'><thead><tr><th>Title</th><th>Release Year</th><th>Rating</th></tr></thead><tbody>"
for row in result:
table_html += f"<tr><td>{row[0]}</td><td>{row[1]}</td><td>{row[2]}</td></tr>"
table_html += "</tbody></table>"
# Display the table
st.markdown(table_html, unsafe_allow_html=True)
if __name__ == "__main__":
main()