Update app.py
Browse files
app.py
CHANGED
|
@@ -47,8 +47,8 @@ def main():
|
|
| 47 |
st.subheader("Uploaded Data")
|
| 48 |
st.write(df.head())
|
| 49 |
|
| 50 |
-
# Ensure the required columns exist
|
| 51 |
-
required_columns = ["
|
| 52 |
missing_columns = [col for col in required_columns if col not in df.columns]
|
| 53 |
|
| 54 |
if missing_columns:
|
|
@@ -56,7 +56,7 @@ def main():
|
|
| 56 |
return
|
| 57 |
|
| 58 |
# Convert marks columns to numeric (if not already numeric)
|
| 59 |
-
marks_columns = ["Maths", "Urdu", "English"]
|
| 60 |
for col in marks_columns:
|
| 61 |
df[col] = pd.to_numeric(df[col], errors='coerce')
|
| 62 |
|
|
@@ -66,3 +66,27 @@ def main():
|
|
| 66 |
# Show the top 10 students based on Total Marks
|
| 67 |
top_performers = df.sort_values(by="Total Marks", ascending=False).head(10)
|
| 68 |
st.subheader("Top 10 Students Based on Total Marks")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
st.subheader("Uploaded Data")
|
| 48 |
st.write(df.head())
|
| 49 |
|
| 50 |
+
# Ensure the required columns exist (excluding "S.No.", "Science", "History", "Islamiat", "Geography")
|
| 51 |
+
required_columns = ["Name", "Class", "Maths", "Urdu", "English"]
|
| 52 |
missing_columns = [col for col in required_columns if col not in df.columns]
|
| 53 |
|
| 54 |
if missing_columns:
|
|
|
|
| 56 |
return
|
| 57 |
|
| 58 |
# Convert marks columns to numeric (if not already numeric)
|
| 59 |
+
marks_columns = ["Maths", "Urdu", "English"]
|
| 60 |
for col in marks_columns:
|
| 61 |
df[col] = pd.to_numeric(df[col], errors='coerce')
|
| 62 |
|
|
|
|
| 66 |
# Show the top 10 students based on Total Marks
|
| 67 |
top_performers = df.sort_values(by="Total Marks", ascending=False).head(10)
|
| 68 |
st.subheader("Top 10 Students Based on Total Marks")
|
| 69 |
+
st.write(top_performers[["Name", "Class", "Total Marks"]])
|
| 70 |
+
|
| 71 |
+
# Add embedding column (for searching students by name or details)
|
| 72 |
+
df['Embedding'] = df.apply(lambda row: model.encode(f"{row['Name']} {row['Class']} {row['Maths']} {row['Urdu']} {row['English']}"), axis=1)
|
| 73 |
+
|
| 74 |
+
# Search functionality
|
| 75 |
+
st.subheader("Search for a Student")
|
| 76 |
+
search_query = st.text_input("Enter the student's name:")
|
| 77 |
+
|
| 78 |
+
if search_query:
|
| 79 |
+
# Find the most similar student based on embeddings
|
| 80 |
+
search_embedding = model.encode(search_query)
|
| 81 |
+
df['Similarity'] = df['Embedding'].apply(lambda emb: (emb @ search_embedding) / (emb.dot(emb) ** 0.5))
|
| 82 |
+
# Get the student with the highest similarity score
|
| 83 |
+
result = df.sort_values(by="Similarity", ascending=False).iloc[0]
|
| 84 |
+
st.write("Search Result:")
|
| 85 |
+
st.write(result[["Name", "Class", "Maths", "Urdu", "English", "Total Marks"]])
|
| 86 |
+
|
| 87 |
+
# Show the updated data with Total Marks column
|
| 88 |
+
st.subheader("Updated Data with Total Marks")
|
| 89 |
+
st.write(df)
|
| 90 |
+
|
| 91 |
+
if __name__ == "__main__":
|
| 92 |
+
main()
|