Spaces:
Runtime error
Runtime error
| import joblib | |
| import pandas as pd | |
| import streamlit as st | |
| from PIL import Image | |
| image = Image.open('dn.png') | |
| image_smart = Image.open('smart.jpg') | |
| image_Zenon = Image.open('Zenon.jpg') | |
| image_Tomorrowland = Image.open('Tomorrowland.jpg') | |
| image_black = Image.open('black.jpeg') | |
| image_eddie = Image.open('eddie.jpg') | |
| image_friend = Image.open('friend.jpg') | |
| image_frozen = Image.open('frozen.jpg') | |
| image_ghost = Image.open('ghost.jpg') | |
| image_home = Image.open('home.jpg') | |
| image_lego = Image.open('lego.jpg') | |
| image_limit = Image.open('limit.jpg') | |
| image_little = Image.open('little.jpg') | |
| image_marvel = Image.open('marvel.jpg') | |
| image_star = Image.open('star.jpg') | |
| image_vamp = Image.open('vamp.jpeg') | |
| image_Wild = Image.open('Wild.jpg') | |
| image_Winged = Image.open('Winged.jpg') | |
| image_X_Men = Image.open('X-Men.jpg') | |
| #RAT_DICT = {"TV-G": 1, | |
| # "TV-PG": 2, | |
| # "G" : 3, | |
| # "PG": 4, | |
| # "TV-Y7": 5, | |
| # "TV-14": 6, | |
| # "PG-13": 7, | |
| # "TV-Y": 8, | |
| # "TV-Y7-FV": 9} | |
| st.image(image, width=None) | |
| model = joblib.load('model_XGB.joblib') | |
| unique_values = joblib.load('unique_values_XGB.joblib') | |
| unique_type = unique_values["type"] | |
| unique_title = unique_values["title"] | |
| unique_director = unique_values["director"] | |
| unique_country = unique_values["country"] | |
| unique_listed_in = unique_values["listed_in"] | |
| unique_description = unique_values["description"] | |
| def main(): | |
| st.title("Movie's Class") | |
| with st.form("questionaire"): | |
| types = st.selectbox("Type", options = unique_type) | |
| title = st.selectbox("Title", options = unique_title) | |
| director = st.selectbox("Director", options = unique_director) | |
| country = st.selectbox("Country", options = unique_country) | |
| listed_in = st.selectbox("Listed_in", options = unique_listed_in) | |
| description = st.selectbox("Description", options = unique_description) | |
| date_added_new = st.slider("Date_added_new", min_value=1800, max_value=2022) | |
| # clicked==True only when the button is clicked | |
| clicked = st.form_submit_button("Predict class") | |
| if clicked: | |
| result=model.predict(pd.DataFrame(({"type": [types], | |
| "title": [title], | |
| "director": [director], | |
| "country": [country], | |
| "listed_in": [listed_in], | |
| "description": [description], | |
| "date_added_new": [date_added_new]}))) | |
| # Show prediction | |
| if result[0] == 0: | |
| result = "TV-G" | |
| #st.image(image_setosa, caption='Iris Setosa', width = 350) | |
| elif result[0] == 1: | |
| result = "PG" | |
| #st.image(image_versicolor, caption='Iris Versicolor', width = 350) | |
| elif result[0] == 2: | |
| result = "TV-PG" | |
| #st.image(image_versicolor, caption='Iris Versicolor', width = 350) | |
| elif result[0] == 3: | |
| result = "PG-13" | |
| #st.image(image_versicolor, caption='Iris Versicolor', width = 350) | |
| elif result[0] == 4: | |
| result = "TV-14" | |
| #st.image(image_versicolor, caption='Iris Versicolor', width = 350) | |
| elif result[0] == 5: | |
| result = "G" | |
| #st.image(image_versicolor, caption='Iris Versicolor', width = 350) | |
| elif result[0] == 6: | |
| result = "TV-Y7" | |
| #st.image(image_versicolor, caption='Iris Versicolor', width = 350) | |
| elif result[0] == 7: | |
| result = "TV-Y" | |
| #st.image(image_versicolor, caption='Iris Versicolor', width = 350) | |
| elif result[0] == 8: | |
| result = "TV-Y7-FV" | |
| #st.image(image_versicolor, caption='Iris Versicolor', width = 350) | |
| else: | |
| result = "unknown" | |
| #st.image(image_virginica, caption='Iris Virginica', width = 350) | |
| st.write(f"Your predicted class is {result}") | |
| #st.success("Your predicted class is " +result) | |
| st.title('I bet U will absolutely love this movie') | |
| with st.form('Hello World'): | |
| text = st.text_input('Input word here.') | |
| clicked = st.form_submit_button('START') | |
| if clicked: | |
| result1=model.predict(pd.DataFrame(({"type": [types], | |
| "title": [title], | |
| "director": [director], | |
| "country": [country], | |
| "listed_in": [listed_in], | |
| "description": [description], | |
| "date_added_new": [date_added_new]}))) | |
| # Show prediction | |
| mood=[] | |
| if result1[0] == 0 : | |
| #mood = "Zenon: The Zequel" | |
| st.image(image_Zenon, caption='Zenon: The Zequel', width = 300) | |
| #mood1 = "Smart Guy" | |
| st.image(image_smart, caption='Smart Guy', width = 300) | |
| elif result1[0] == 1: | |
| #mood = "Home Sweet Home Alone" | |
| st.image(image_home, caption='Home Sweet Home Alone', width = 300) | |
| #mood1 = "Tomorrowland" | |
| st.image(image_Tomorrowland, caption='Tomorrowland', width = 300) | |
| elif result1[0] == 2: | |
| #mood = "Wild Yellowstone" | |
| st.image(image_Wild, caption='Wild Yellowstone', width = 300) | |
| #mood1 = "Winged Seduction: Birds of Paradise" | |
| st.image(image_Winged, caption='Winged Seduction: Birds of Paradise', width = 300) | |
| elif result1[0] == 3: | |
| #mood = "X-Men: First Class" | |
| st.image(image_X_Men, caption='X-Men: First Class', width = 300) | |
| #mood1 = "Eddie the Eagle" | |
| st.image(image_eddie, caption='Eddie the Eagle', width = 300) | |
| elif result1[0] == 4: | |
| #mood = "Limitless with Chris Hemsworth" | |
| st.image(image_limit, caption='Limitless with Chris Hemsworth', width = 300) | |
| #mood1 = "Marvel's Agent Carter" | |
| st.image(image_marvel, caption="Marvel's Agent Carter", width = 300) | |
| elif result1[0] == 5: | |
| #mood = "Frozen Fever" | |
| st.image(image_frozen, caption='Frozen Fever', width = 300) | |
| #mood1 = "Blackbeard's Ghost" | |
| st.image(image_black, caption="Blackbeard's Ghost", width = 300) | |
| elif result1[0] == 6: | |
| #mood = "The Ghost and Molly McGee" | |
| st.image(image_ghost, caption="The Ghost and Molly McGee", width = 300) | |
| #mood1 = "Disney Vampirina" | |
| st.image(image_vamp, caption="Disney Vampirina", width = 300) | |
| elif result1[0] == 7: | |
| #mood = "Disney's Little Einsteins" | |
| st.image(image_little, caption="Disney's Little Einsteins", width = 300) | |
| #mood1 = "My Friends Tigger & Pooh" | |
| st.image(image_friend, caption="My Friends Tigger & Pooh", width = 300) | |
| elif result1[0] == 8: | |
| #mood = "LEGO Star Wars Terrifying Tales" | |
| st.image(image_lego, caption="LEGO Star Wars Terrifying Tales", width = 300) | |
| #mood1 = "Star Wars: Ewoks" | |
| st.image(image_star, caption="Star Wars: Ewoks", width = 300) | |
| else: | |
| st.write(f"Unknown") | |
| #st.success('Your movie is '+ mood) | |
| #st.success('Your movie is '+ mood1) | |
| if __name__ == '__main__': | |
| main() |