Skip to content

Commit 5053aae

Browse files
committed
add review submission page
1 parent 7e87ed3 commit 5053aae

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed

Web_app/movie_reviews.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Name,Movie,Review
2+

Web_app/pages/ReviewSubmission.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import streamlit as st
2+
import os
3+
import pandas as pd
4+
5+
# Set the path for storing the reviews
6+
reviews_file = "movie_reviews.csv"
7+
8+
# Initialize the reviews file if it doesn't exist
9+
if not os.path.exists(reviews_file):
10+
df = pd.DataFrame(columns=["Name", "Movie", "Review"])
11+
df.to_csv(reviews_file, index=False)
12+
13+
# Read the existing reviews from the file
14+
df = pd.read_csv(reviews_file)
15+
16+
# Initialize session state for showing the review form
17+
if "show_review_form" not in st.session_state:
18+
st.session_state.show_review_form = False
19+
20+
st.title("🎬 Submit Your Movie Review")
21+
22+
st.markdown(
23+
"<div style='height: 5px; background: linear-gradient(to right, #FF5733, #FFC300, #DAF7A6, #33FF57, #3380FF);'></div>",
24+
unsafe_allow_html=True,
25+
)
26+
27+
# Updated Custom CSS for Reddit-style reviews with dynamic sizing
28+
st.markdown(
29+
"""
30+
<style>
31+
.review-box {
32+
background-color: #f8f9fa;
33+
padding: 12px;
34+
border-radius: 4px;
35+
margin-bottom: 16px;
36+
border: 1px solid #e3e6e8;
37+
width: auto;
38+
max-width: 100%;
39+
height: auto;
40+
overflow-wrap: break-word;
41+
word-wrap: break-word;
42+
hyphens: auto;
43+
}
44+
.review-header {
45+
color: #1a1a1b;
46+
font-size: 12px;
47+
font-weight: 400;
48+
line-height: 16px;
49+
display: flex;
50+
align-items: center;
51+
margin-bottom: 8px;
52+
flex-wrap: wrap;
53+
}
54+
.review-author {
55+
color: #1c1c1c;
56+
font-weight: 700; /* Changed to bold */
57+
margin-right: 4px;
58+
text-transform: capitalize;
59+
}
60+
.review-movie {
61+
color: red;
62+
text-transform: capitalize;
63+
}
64+
.review-content {
65+
font-size: 14px;
66+
line-height: 21px;
67+
font-weight: 400;
68+
color: #1a1a1b;
69+
white-space: pre-wrap; /* Preserves line breaks and spaces */
70+
}
71+
.toggle-button {
72+
cursor: pointer;
73+
color: #0079D3;
74+
}
75+
</style>
76+
""",
77+
unsafe_allow_html=True,
78+
)
79+
80+
# Toggle for review form visibility
81+
show_review_form = st.checkbox(
82+
"➕ Submit Review", value=st.session_state.show_review_form, key="review_checkbox"
83+
)
84+
85+
# Update session state based on checkbox
86+
st.session_state.show_review_form = show_review_form
87+
88+
# Form for submitting reviews
89+
if st.session_state.show_review_form:
90+
with st.form(key="review_form"):
91+
name = st.text_input("Your Name")
92+
movie_name = st.text_input("Movie Name")
93+
review = st.text_area("Your Review", height=80)
94+
submit_button = st.form_submit_button(label="Submit Review")
95+
96+
if submit_button:
97+
if name and movie_name and review:
98+
new_review = pd.DataFrame(
99+
{
100+
"Name": [name],
101+
"Movie": [movie_name],
102+
"Review": [review],
103+
}
104+
)
105+
df = pd.concat([df, new_review], ignore_index=True)
106+
df.to_csv(reviews_file, index=False)
107+
st.success("Thank you for your review!")
108+
st.session_state.show_review_form = False
109+
st.rerun()
110+
else:
111+
st.error("Please fill in all fields before submitting.")
112+
113+
# Display the reviews in a Reddit-style comment format
114+
st.subheader("📜 Reviews")
115+
116+
if not df.empty:
117+
for index, row in df.iterrows():
118+
st.markdown(
119+
f"""
120+
<div class="review-box">
121+
<div class="review-header">
122+
<span class="review-author">{row['Name']}</span>
123+
<span class="review-movie">{row['Movie']}</span>
124+
</div>
125+
<div class="review-content">{row['Review']}</div>
126+
</div>
127+
""",
128+
unsafe_allow_html=True,
129+
)
130+
else:
131+
st.write("No reviews yet. Be the first to leave one!")

0 commit comments

Comments
 (0)