Hemg commited on
Commit
21e349b
1 Parent(s): bbc742b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +115 -0
app.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import numpy as np
4
+ import pandas as pd
5
+ from huggingface_hub import hf_hub_download
6
+ from sklearn.preprocessing import StandardScaler, OneHotEncoder, LabelEncoder
7
+
8
+ # Load the trained model and scaler objects from file
9
+
10
+
11
+ REPO_ID = "Hemg/modelxxx" # hugging face repo ID
12
+ MoDEL_FILENAME = "studentpredict.joblib" # model file name
13
+ SCALER_FILENAME ="studentscaler.joblib" # scaler file name
14
+
15
+ model = joblib.load(hf_hub_download(repo_id=REPO_ID, filename=MoDEL_FILENAME))
16
+
17
+ scaler = joblib.load(hf_hub_download(repo_id=REPO_ID, filename=SCALER_FILENAME))
18
+
19
+ def encode_categorical_columns(df):
20
+ label_encoder = LabelEncoder()
21
+ ordinal_columns = df.select_dtypes(include=['object']).columns
22
+
23
+ for col in ordinal_columns:
24
+ df[col] = label_encoder.fit_transform(df[col])
25
+
26
+ nominal_columns = df.select_dtypes(include=['object']).columns.difference(ordinal_columns)
27
+ df = pd.get_dummies(df, columns=nominal_columns, drop_first=True)
28
+
29
+ return df
30
+
31
+ # Define the prediction function
32
+ def predict_performance(Location, College_Fee, GPA, Year, Course_Interested, College,
33
+ Faculty, Source, visited_college_for_inquiry_only, attended_event_name,
34
+ attended_any_events, Presenter, visited_with_parents):
35
+
36
+ # Debug print 1: Print all input values
37
+ print("\nInput Values:")
38
+ print(f"Location: {Location}")
39
+ print(f"College_Fee: {College_Fee}")
40
+ print(f"GPA: {GPA}")
41
+ print(f"Year: {Year}")
42
+ print(f"Course_Interested: {Course_Interested}")
43
+ print(f"Faculty: {Faculty}")
44
+ print(f"Source: {Source}")
45
+ print(f"Visited for inquiry: {visited_college_for_inquiry_only}")
46
+ print(f"Event name: {attended_event_name}")
47
+ print(f"Attended events: {attended_any_events}")
48
+ print(f"Presenter: {Presenter}")
49
+ print(f"Visited with parents: {visited_with_parents}")
50
+
51
+ input_data = [[Location, College_Fee, GPA, Year, Course_Interested, College,
52
+ Faculty, Source, visited_college_for_inquiry_only, attended_event_name,
53
+ attended_any_events, Presenter, visited_with_parents]]
54
+
55
+ feature_names = ["Location", "College_Fee", "GPA", "Year", "Course_Interested", "College",
56
+ "Faculty", "Source", "visited_college_for_inquiry_only", "attended_event_name",
57
+ "attended_any_events", "Presenter", "visited_with_parents"]
58
+
59
+ input_df = pd.DataFrame(input_data, columns=feature_names)
60
+
61
+ # Debug print 2: Show DataFrame before encoding
62
+ print("\nDataFrame before encoding:")
63
+ print(input_df)
64
+
65
+ df = encode_categorical_columns(input_df)
66
+
67
+ # Debug print 3: Show DataFrame after encoding
68
+ print("\nDataFrame after encoding:")
69
+ print(df)
70
+
71
+ scaled_input = scaler.transform(df)
72
+
73
+ # Debug print 4: Show scaled input
74
+ print("\nScaled input:")
75
+ print(scaled_input)
76
+
77
+ prediction = model.predict(scaled_input)[0]
78
+
79
+ # Debug print 5: Show prediction details
80
+ print("\nPrediction details:")
81
+ print(f"Raw prediction: {prediction}")
82
+ prediction_probability = 1 / (1 + np.exp(-prediction))
83
+ print(f"Probability: {prediction_probability}")
84
+ prediction_percentage = prediction_probability * 100
85
+ print(f"Percentage: {prediction_percentage}")
86
+
87
+ return f"Chance of Admission: {prediction_percentage:.1f}%"
88
+
89
+ iface = gr.Interface(
90
+ fn=predict_performance,
91
+ inputs=[
92
+ gr.Radio(["Kathmandu", "Bhaktapur", "Lalitpur", "Kritipur"], label="Location"),
93
+ gr.Slider(minimum=1000000, maximum=1700000, label="College Fee"),
94
+ gr.Slider(minimum=2, maximum=3, label="GPA"), # Fixed GPA input
95
+ gr.Slider(minimum=2019, maximum=2025, step=1, label="Year"),
96
+ gr.Radio(["MSc IT & Applied Security", "BSc (Hons) Computing", "BSc (Hons) Computing with Artificial Intelligence",
97
+ "BSc (Hons) Computer Networking & IT Security", "BSc (Hons) Multimedia Technologies", "MBA",
98
+ "BA (Hons) Accounting & Finance", "BA (Hons) Business Administration"], label="Course_Interested"),
99
+ gr.Radio(["Science", "Management", "Humanities"], label="Faculty"),
100
+ gr.Radio(["Event", "Facebook", "Instagram", "Offline", "Recommendation"], label="Source"),
101
+ gr.Radio(["Yes", "No"], label="visited_college_for_inquery_only"),
102
+ gr.Radio(["New Year", "Dashain", "Orientation", "Fresher's Party", "Holi Festival", "Welcome Ceremony"],
103
+ label="attended_event_name"), # Changed from Slider to Radio
104
+ gr.Radio(["Yes", "No"], label="attended_any_event"),
105
+ gr.Radio(["Ram", "Gita", "Manish", "Shyam", "Raj", "Hari", "Rina", "Shree"], label="Presenter"),
106
+ gr.Radio(["Yes", "No"], label="visited_with_parents")
107
+ ],
108
+ outputs="text",
109
+ title="chances of student admission",
110
+ description="chances of student admission"
111
+ )
112
+
113
+ # Run the app
114
+ if __name__ == "__main__":
115
+ iface.launch(share=True)