Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,86 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import numpy as np
|
| 3 |
-
import torch
|
| 4 |
-
import torch.nn as nn
|
| 5 |
-
import torch.nn.functional as F
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import torch
|
| 4 |
+
import torch.nn as nn
|
| 5 |
+
import torch.nn.functional as F
|
| 6 |
+
import base64
|
| 7 |
+
|
| 8 |
+
# Function to set background image
|
| 9 |
+
def set_background(image_file):
|
| 10 |
+
with open(image_file, "rb") as image:
|
| 11 |
+
encoded_string = base64.b64encode(image.read()).decode()
|
| 12 |
+
st.markdown(
|
| 13 |
+
f"""
|
| 14 |
+
<style>
|
| 15 |
+
.stApp {{
|
| 16 |
+
background-image: url(data:image/png;base64,{encoded_string});
|
| 17 |
+
background-size: cover;
|
| 18 |
+
}}
|
| 19 |
+
</style>
|
| 20 |
+
""",
|
| 21 |
+
unsafe_allow_html=True
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Set the background image
|
| 25 |
+
set_background('path_to_your_image.png')
|
| 26 |
+
|
| 27 |
+
# Custom title with blue color
|
| 28 |
+
st.markdown("<h1 style='color: blue;'>Placement Analysis</h1>", unsafe_allow_html=True)
|
| 29 |
+
|
| 30 |
+
# Define the same model architecture
|
| 31 |
+
class ANN_Model(nn.Module):
|
| 32 |
+
def __init__(self, input_cols=10, hidden1=20, hidden2=20, output=1):
|
| 33 |
+
super().__init__()
|
| 34 |
+
self.f_connected1 = nn.Linear(input_cols, hidden1)
|
| 35 |
+
self.f_connected2 = nn.Linear(hidden1, hidden2)
|
| 36 |
+
self.out = nn.Linear(hidden2, output)
|
| 37 |
+
|
| 38 |
+
def forward(self, x):
|
| 39 |
+
x = F.relu(self.f_connected1(x))
|
| 40 |
+
x = F.relu(self.f_connected2(x))
|
| 41 |
+
x = torch.sigmoid(self.out(x)) # Sigmoid for binary classification
|
| 42 |
+
return x
|
| 43 |
+
|
| 44 |
+
# Load the model
|
| 45 |
+
model = ANN_Model() # Initialize the model
|
| 46 |
+
model.load_state_dict(torch.load("ANN_model.pth")) # Load saved weights
|
| 47 |
+
model.eval() # Set to evaluation mode
|
| 48 |
+
|
| 49 |
+
# User inputs
|
| 50 |
+
cgpa = st.number_input("Enter your CGPA", min_value=0.0, max_value=10.0, step=0.01)
|
| 51 |
+
internships = st.number_input("Number of Internships", min_value=0, max_value=10, step=1)
|
| 52 |
+
projects = st.number_input("Number of Projects", min_value=0, max_value=20, step=1)
|
| 53 |
+
certifications = st.selectbox("Do you have certifications?", ["Yes", "No"])
|
| 54 |
+
certifications = 1 if certifications == "Yes" else 0
|
| 55 |
+
AptitudeTestScore = st.number_input("Aptitude Test Score", min_value=0, max_value=100, step=1)
|
| 56 |
+
SoftSkillsRating = st.number_input("Soft Skills Rating", min_value=0, max_value=5)
|
| 57 |
+
ExtracurricularActivities = st.selectbox("Extracurricular Activities", ["Yes", "No"])
|
| 58 |
+
ExtracurricularActivities = 1 if ExtracurricularActivities == "Yes" else 0
|
| 59 |
+
PlacementTraining = st.selectbox("Placement Training", ["Yes", "No"])
|
| 60 |
+
PlacementTraining = 1 if PlacementTraining == "Yes" else 0
|
| 61 |
+
SSC_Marks = st.number_input("SSC Marks", min_value=0, max_value=100, step=1)
|
| 62 |
+
HSC_Marks = st.number_input("HSC Marks", min_value=0, max_value=100, step=1)
|
| 63 |
+
|
| 64 |
+
# Predict Button
|
| 65 |
+
if st.button("Predict Placement"):
|
| 66 |
+
# Prepare input for model
|
| 67 |
+
input_data = [cgpa, internships, projects, certifications, AptitudeTestScore, SoftSkillsRating,
|
| 68 |
+
ExtracurricularActivities, PlacementTraining, SSC_Marks, HSC_Marks]
|
| 69 |
+
# Example: Making a prediction
|
| 70 |
+
with torch.no_grad():
|
| 71 |
+
output = model(torch.tensor(input_data)).numpy()
|
| 72 |
+
if output >= 0.5:
|
| 73 |
+
st.markdown(
|
| 74 |
+
"""
|
| 75 |
+
<div style='background-color: #d4edda; padding: 10px; border-radius: 5px;'>
|
| 76 |
+
<h4 style='color: #155724;'>🎉 Congratulations! You are likely to get placed.</h4>
|
| 77 |
+
</div>
|
| 78 |
+
""",
|
| 79 |
+
unsafe_allow_html=True
|
| 80 |
+
)
|
| 81 |
+
else:
|
| 82 |
+
st.markdown(
|
| 83 |
+
"""
|
| 84 |
+
<div style='background-color: #f8d7da;
|
| 85 |
+
::contentReference[oaicite:2]{index=2}
|
| 86 |
+
|