import streamlit as st import pandas as pd import pickle with open('gb_model_best.pkl', 'rb') as f: gb_model_best = pickle.load(f) # Create a Streamlit app st.title("Movie Revenue Predictor 🎥") st.image("https://i0.wp.com/indyfilmlibrary.com/wp-content/uploads/2024/01/iStock-92043739-e1704448388494.jpg?fit=1329%2C578&ssl=1") st.write("This data is trained from imdb with %70 r2 score. Learn which artibutes make a money machine film.") # Create input fields for the user popularity = st.slider("Popularity (0-100, 100 being Avatar):", min_value=1, max_value=100, value=50) runtime = st.number_input("Runtime (in minutes):", min_value=1, step=1, value=120) is_original_en = st.selectbox("Is the orginal language English?", ["Yes", "No"], index=0) # Create a conditional input field for budget budget_known = st.selectbox("Is the budget known?", ["Yes", "No"], index=0) if budget_known == "Yes": budget_M = st.number_input("Budget (in millions of dollars):", min_value=1, step=1, value=150) else: budget_M = 10 # Create a submit button submitted = st.button("Predict Revenue") # When the user submits the form, make a prediction if submitted: popularity_value = popularity / 2 # Create a DataFrame with the user's input data input_data = pd.DataFrame({ "popularity": [popularity_value], "runtime": [runtime], "budget_known": [int(budget_known == "Yes")], "budget_M": [budget_M], "is_original_en": [int(is_original_en == "Yes")] }) # Make a prediction using the trained model input_data = input_data[gb_model_best.feature_names_in_] prediction = gb_model_best.predict(input_data)[0] # Display the predicted revenue st.write(f"Predicted Box Office Revenue is:") st.title(f"${prediction:.2f} million.")