From 0955bf756314bdd2d6bbc20416744431dc7b96b1 Mon Sep 17 00:00:00 2001 From: MIGHTY1o1 Date: Thu, 17 Oct 2024 03:23:20 +0530 Subject: [PATCH] add polls --- Web_app/__pycache__/utils.cpython-38.pyc | Bin 0 -> 1210 bytes Web_app/pages/MoviePol.py | 119 +++++++++++++++++++++++ Web_app/pollmovies.csv | 22 +++++ 3 files changed, 141 insertions(+) create mode 100644 Web_app/__pycache__/utils.cpython-38.pyc create mode 100644 Web_app/pages/MoviePol.py create mode 100644 Web_app/pollmovies.csv diff --git a/Web_app/__pycache__/utils.cpython-38.pyc b/Web_app/__pycache__/utils.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3d1d30f2bd46f98f7bc79753469886619d54f7a6 GIT binary patch literal 1210 zcmZWo&2AGh5VpO)Nn2V#ty+Xcq@Hph;arsp)QS^Sh_nT*gd%tCZLIDew$svRbD=$O z;lLXtM_z?T@Rd`=8*pO0QA$<3^31nm&vx|@t;qT;=3kIBPt0S$EYfFBhHZi30%wQn{dt%9-=iNiarRu7|@OaSOs;tTt2e)*w%SY5h8Qg+Lie?#xk?I|84u72H%`iP2`z|>1LsjtN^T#K)Tp0h@Lyoj6R9u7%}7m0iXC;wI6hEX?X2LQAr)O!PF=9FxpG1f3K zbrV6WPVlUuEMo4|&WN`!7ePzfhevm_`L<9(i!E9{ z@;?6z`H$_WcC^KHi5KR#)LB*+HCmoaGOneFRbAIQd(u90%e%VS>so}{P_kjlckDbU MD}t2UkAx5Z0-(t&>Hq)$ literal 0 HcmV?d00001 diff --git a/Web_app/pages/MoviePol.py b/Web_app/pages/MoviePol.py new file mode 100644 index 00000000..447226a1 --- /dev/null +++ b/Web_app/pages/MoviePol.py @@ -0,0 +1,119 @@ +import streamlit as st +import pandas as pd +import os + +# Path to the poll movies file +movies_file = "pollmovies.csv" + +# Load movies from pollmovies.csv if it exists +if os.path.exists(movies_file): + df_movies = pd.read_csv(movies_file) +else: + st.error( + "The file 'pollmovies.csv' does not exist. Please make sure it is available in the directory." + ) + st.stop() + +# Ensure column names are stripped of whitespace +df_movies.columns = df_movies.columns.str.strip() + +# Convert Votes column to numeric, filling NaNs with 0 (in case of non-numeric data) +df_movies["Votes"] = ( + pd.to_numeric(df_movies["Votes"], errors="coerce").fillna(0).astype(int) +) + +# Set up dashboard title and header styling +st.title("🎜 Movie Poll Dashboard") +st.markdown("
", unsafe_allow_html=True) + +# Search bar to find movies +search_query = st.text_input("Search for a movie") +filtered_df = ( + df_movies[df_movies["Title"].str.contains(search_query, case=False, na=False)] + if search_query + else df_movies +) + +# Pagination variables +polls_per_page = 5 +page_number = st.number_input( + "Page Number", + min_value=1, + max_value=(len(filtered_df) // polls_per_page) + 1, + step=1, +) +start_index = (page_number - 1) * polls_per_page +end_index = start_index + polls_per_page + +# Create a two-column layout for main dashboard content +col1, col2 = st.columns([2, 1]) + +with col1: + st.subheader("📜 Available Movies for Polling") + + # Display each movie in a "card" style format with pagination + for index, row in filtered_df.iloc[start_index:end_index].iterrows(): + with st.container(): + st.markdown( + f""" +
+

{row['Title']}

+

Genre: {row['Genre']} | Industry: {row['Industry']}

+

Votes: {row['Votes']}

+
+ """, + unsafe_allow_html=True, + ) + if st.button(f"Vote for {row['Title']}", key=index): + df_movies.at[index, "Votes"] += 1 + df_movies.to_csv(movies_file, index=False) + st.success(f"Thanks for voting for {row['Title']}!") + +with col2: + # Add new movie form in the right column + st.subheader("âž• Add a New Movie") + with st.form("add_movie_form"): + new_title = st.text_input("Movie Title") + new_genre = st.selectbox( + "Genre", + [ + "Action", + "Comedy", + "Crime", + "Drama", + "Romance", + "Sci-Fi", + "Adventure", + "Musical", + ], + ) + new_industry = st.selectbox("Industry", ["Hollywood", "Bollywood"]) + submit_movie = st.form_submit_button("Add Movie") + + if submit_movie: + if new_title: + new_movie = { + "Title": [new_title], + "Genre": [new_genre], + "Industry": [new_industry], + "Votes": [0], + } + new_movie_df = pd.DataFrame(new_movie) + df_movies = pd.concat([df_movies, new_movie_df], ignore_index=True) + df_movies.to_csv(movies_file, index=False) + st.success(f"{new_title} has been added to the poll!") + else: + st.error("Please enter a movie title.") + +# Add a button to view poll results +if st.button("View Poll Results"): + # Add a section to display poll results with sorting + st.markdown("
", unsafe_allow_html=True) + st.subheader("📊 Poll Results") + + # Sort and display poll results in a more structured table format + sorted_df = df_movies[["Title", "Genre", "Industry", "Votes"]].sort_values( + by="Votes", ascending=False + ) + st.dataframe(sorted_df) diff --git a/Web_app/pollmovies.csv b/Web_app/pollmovies.csv new file mode 100644 index 00000000..2d2f7f25 --- /dev/null +++ b/Web_app/pollmovies.csv @@ -0,0 +1,22 @@ +Title,Genre,Industry,Votes +Inception,Sci-Fi,Hollywood,5 +Titanic,Romance,Hollywood,1 +The Godfather,Crime,Hollywood,2 +Avengers: Endgame,Action,Hollywood,0 +Shawshank Redemption,Drama,Hollywood,0 +Forrest Gump,Drama,Hollywood,0 +Interstellar,Sci-Fi,Hollywood,0 +The Dark Knight,Action,Hollywood,0 +Pulp Fiction,Crime,Hollywood,0 +The Matrix,Sci-Fi,Hollywood,0 +3 Idiots,Drama,Bollywood,0 +Dangal,Drama,Bollywood,0 +Dilwale Dulhania Le Jayenge,Romance,Bollywood,0 +Sholay,Action,Bollywood,0 +Zindagi Na Milegi Dobara,Adventure,Bollywood,0 +Bahubali,Action,Bollywood,0 +Kabir Singh,Romance,Bollywood,0 +Queen,Drama,Bollywood,0 +Gully Boy,Musical,Bollywood,0 +PK,Comedy,Bollywood,3 +ddlj,Adventure,Hollywood,1