-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
119 lines (102 loc) · 4.49 KB
/
main.py
File metadata and controls
119 lines (102 loc) · 4.49 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import streamlit as st
import pandas as pd
import subprocess
import sys
try:
import joblib
except ImportError:
subprocess.run([sys.executable, "-m", "pip", "install", "joblib"])
import joblib # Retry import
from pytorch_tabnet.tab_model import TabNetRegressor
# Load the dataset
df = pd.read_csv("/Users/chandrus/development/imdb_top_1000.csv")
# Load the trained model & scaler
model = TabNetRegressor()
model.load_model("tabnet_imdb.zip")
scaler = joblib.load("scaler.pkl")
# Configure page
st.set_page_config(page_title="🍿 Movie Rating Predictor", layout="wide")
# Custom CSS for better styling
st.markdown("""
<style>
.big-font { font-size:50px !important; }
.result-box { padding: 20px; border-radius: 10px; margin: 10px 0; }
.st-emotion-cache-1v0mbdj { width: 100%; }
</style>
""", unsafe_allow_html=True)
# Split layout into two columns
col1, col2 = st.columns([1, 2], gap="large")
# Left Column - Inputs
with col1:
st.header("🎬 Movie Details")
with st.form("prediction_form"):
movie_title = st.text_input("Movie Title", placeholder="Enter movie title...")
director = st.selectbox("Director", options=df["Director"].dropna().unique(), index=0)
cast = st.multiselect(
"Cast Members",
options=pd.concat([df["Star1"], df["Star2"], df["Star3"], df["Star4"]]).unique(),
placeholder="Select actors..."
)
runtime = st.slider("Runtime (minutes)", 60, 240, 120)
genre = st.selectbox("Genre", options=df["Genre"].dropna().unique(), index=0)
metascore = st.slider("Metascore", 0, 100, 70)
votes = st.number_input("Number of Votes", 1000, 2000000, 10000)
submitted = st.form_submit_button("🚀 Predict Rating!")
# Right Column - Results
with col2:
st.header("🌟 Prediction Results")
if submitted:
try:
# Make prediction
input_features = [runtime, metascore, votes]
scaled_features = scaler.transform([input_features])
prediction = model.predict(scaled_features)
predicted_rating = round(prediction[0][0], 1)
# Display rating with style
st.markdown(f"""
<div class="result-box" style="background-color: {'#4CAF50' if predicted_rating >= 7 else '#FF9800'};">
<h2 style="color: white;">{movie_title or 'Your Movie'}</h2>
<p class="big-font" style="color: white; margin: 0;">{predicted_rating:.1f}/10</p>
</div>
""", unsafe_allow_html=True)
# Rating feedback
if predicted_rating >= 8:
st.balloons()
st.success("⭐ Blockbuster Alert! This could be the next big hit!")
st.image("https://i.gifer.com/7efs.gif", caption="Crowd cheering!")
elif 6 <= predicted_rating < 8:
st.info("🎥 Solid Performer! Worth a watch!")
else:
st.warning("💤 Might need some improvements...")
# Progress bar visualization
st.markdown(f"""
<div style="margin: 20px 0;">
<div style="background: #eee; border-radius: 5px; padding: 3px;">
<div style="background: {'#4CAF50' if predicted_rating >= 7 else '#FF9800'};
width: {predicted_rating * 10}%;
height: 20px;
border-radius: 3px;"></div>
</div>
<p style="text-align: center; margin: 5px 0;">IMDb Score Meter</p>
</div>
""", unsafe_allow_html=True)
# Movie details card
with st.expander("📄 Movie Details"):
cols = st.columns(2)
with cols[0]:
st.write(f"**Director:** {director}")
st.write(f"**Runtime:** {runtime} minutes")
st.write(f"**Metascore:** {metascore}")
with cols[1]:
st.write(f"**Genre:** {genre}")
st.write(f"**Votes:** {votes:,}")
st.write(f"**Cast:** {', '.join(cast) if cast else 'Not specified'}")
except Exception as e:
st.error(f"🚨 Prediction failed: {str(e)}")
else:
st.markdown("""
<div style="text-align: center; padding: 50px 20px; border: 2px dashed #4CAF50; border-radius: 10px;">
<h3>👈 Fill in the details and click Predict!</h3>
<p>Your prediction will appear here</p>
</div>
""", unsafe_allow_html=True)