Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,56 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
import pandas as pd
|
| 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 |
with gr.Blocks() as demo:
|
| 39 |
-
gr.Markdown("##
|
| 40 |
|
| 41 |
with gr.Row():
|
| 42 |
name = gr.Textbox(label="Student Name")
|
| 43 |
roll_no = gr.Textbox(label="Roll Number")
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
bed_no = gr.Dropdown([f"Bed {i}" for i in range(1, 11)], label="Select Bed No")
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
|
|
|
| 54 |
|
| 55 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
# Hostels and rooms
|
| 6 |
+
hostels = ["Hostel A", "Hostel B", "Hostel C"]
|
| 7 |
+
rooms = list(range(1, 21)) # 20 rooms per hostel
|
| 8 |
+
|
| 9 |
+
# DataFrame to store allotments
|
| 10 |
+
allotments = pd.DataFrame(columns=["Name", "Roll No", "Father's Name", "Hostel", "Room No"])
|
| 11 |
+
|
| 12 |
+
# Function to allot hostel and room
|
| 13 |
+
def allot_hostel(name, roll_no, father_name):
|
| 14 |
+
global allotments
|
| 15 |
+
|
| 16 |
+
# Check if already allotted
|
| 17 |
+
existing = allotments[allotments["Roll No"] == roll_no]
|
| 18 |
+
if not existing.empty:
|
| 19 |
+
return f"Already allotted: {existing.iloc[0]['Hostel']} - Room {existing.iloc[0]['Room No']}"
|
| 20 |
+
|
| 21 |
+
# Random hostel & room
|
| 22 |
+
hostel = random.choice(hostels)
|
| 23 |
+
room = random.choice(rooms)
|
| 24 |
+
|
| 25 |
+
# Save in DataFrame
|
| 26 |
+
new_row = pd.DataFrame([[name, roll_no, father_name, hostel, room]],
|
| 27 |
+
columns=allotments.columns)
|
| 28 |
+
allotments = pd.concat([allotments, new_row], ignore_index=True)
|
| 29 |
+
|
| 30 |
+
return f"Allotted: {hostel}, Room {room}"
|
| 31 |
+
|
| 32 |
+
# Function to show all allotments
|
| 33 |
+
def show_allotments():
|
| 34 |
+
if allotments.empty:
|
| 35 |
+
return "No allotments yet."
|
| 36 |
+
return allotments
|
| 37 |
+
|
| 38 |
+
# Gradio UI
|
| 39 |
with gr.Blocks() as demo:
|
| 40 |
+
gr.Markdown("## 🏠 Hostel Allotment System")
|
| 41 |
|
| 42 |
with gr.Row():
|
| 43 |
name = gr.Textbox(label="Student Name")
|
| 44 |
roll_no = gr.Textbox(label="Roll Number")
|
| 45 |
+
father_name = gr.Textbox(label="Father's Name")
|
| 46 |
|
| 47 |
+
allot_btn = gr.Button("Allot Hostel")
|
| 48 |
+
output = gr.Textbox(label="Allotment Result")
|
|
|
|
| 49 |
|
| 50 |
+
show_btn = gr.Button("Show Allotted Data")
|
| 51 |
+
table = gr.Dataframe(label="Allotment Records")
|
| 52 |
|
| 53 |
+
allot_btn.click(allot_hostel, inputs=[name, roll_no, father_name], outputs=output)
|
| 54 |
+
show_btn.click(show_allotments, outputs=table)
|
| 55 |
|
| 56 |
demo.launch()
|