Spaces:
Runtime error
Runtime error
parthasonu505
commited on
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import streamlit as st
|
3 |
+
import streamlit.components.v1 as components
|
4 |
+
from PIL import Image
|
5 |
+
from io import BytesIO
|
6 |
+
|
7 |
+
|
8 |
+
# Load the Excel file
|
9 |
+
st.set_page_config(layout="wide")
|
10 |
+
|
11 |
+
ipcode=""
|
12 |
+
ipname=""
|
13 |
+
ipsection=''
|
14 |
+
ipclass=''
|
15 |
+
r1c1,_,r1c2 = st.columns([4,0.5,4])
|
16 |
+
section_set=()
|
17 |
+
with r1c1:
|
18 |
+
st.title('Data Entry')
|
19 |
+
uploaded_file = st.file_uploader("Choose a file", type = 'xlsx')
|
20 |
+
if uploaded_file is not None:
|
21 |
+
df = pd.read_excel(uploaded_file, sheet_name='Sheet1')
|
22 |
+
section_set=tuple(set(list(df['Section'])))
|
23 |
+
r1lc1,r1lc2 = st.columns([2,2])
|
24 |
+
with r1lc1:
|
25 |
+
Section_name= st.selectbox( "Select Section",section_set)
|
26 |
+
with r1lc2:
|
27 |
+
roll_no = st.text_input('Enter Roll Number')
|
28 |
+
cb0,cb1,cb2,_=st.columns([1,1,1,3])
|
29 |
+
with cb2:
|
30 |
+
go=st.button('Go')
|
31 |
+
with cb1:
|
32 |
+
next=st.button('Next >')
|
33 |
+
with cb0:
|
34 |
+
prev=st.button('< Prev')
|
35 |
+
|
36 |
+
picture = st.camera_input("Take a picture")
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
if go or picture:
|
41 |
+
# Filter the dataframe based on the input
|
42 |
+
filtered_df = df[(df['Section'] == Section_name) & (df['Roll'] == int(roll_no))]
|
43 |
+
|
44 |
+
if not filtered_df.empty:
|
45 |
+
with r1c2:
|
46 |
+
st.title('Your Data')
|
47 |
+
r2c1,r2c2 = st.columns([2,2])
|
48 |
+
# Display the data in text fields
|
49 |
+
with r2c1:
|
50 |
+
ipname=st.text_input('Name', filtered_df['Name'].values[0])
|
51 |
+
ipaddress=st.text_input('Address', filtered_df['Address'].values[0])
|
52 |
+
ipphone=st.text_input('Phone', filtered_df['Phone'].values[0])
|
53 |
+
ipclass=st.text_input('Class', filtered_df['Class'].values[0])
|
54 |
+
ipsection=st.text_input('Section', filtered_df['Section'].values[0])
|
55 |
+
iproll=st.text_input('Roll', filtered_df['Roll'].values[0])
|
56 |
+
with r2c2:
|
57 |
+
ipcode=st.text_input('Code', filtered_df['Code'].values[0])
|
58 |
+
ippic=st.text_input('Picture', filtered_df['Picture'].values[0])
|
59 |
+
ipgurno=st.text_input('Guardian Number', filtered_df['Guardian Number'].values[0])
|
60 |
+
ipfn=st.text_input('Father\'s Name', filtered_df['Father\'s Name'].values[0])
|
61 |
+
inmn=st.text_input('Mother\'s Name', filtered_df['Mother\'s Name'].values[0])
|
62 |
+
inbg=st.text_input('Blood Group', filtered_df['Blood Group'].values[0])
|
63 |
+
indob=st.text_input('DOB', str(filtered_df['DOB'].values[0]))
|
64 |
+
if picture:
|
65 |
+
df.loc[df.Code == ipcode, 'Picture'] =f"Photo/{ipclass}/{ipsection}/{ipcode}_{ipname}.jpg"
|
66 |
+
|
67 |
+
with open(f"Photo/{ipclass}/{ipsection}/{ipcode}_{ipname}.jpg", 'wb') as f:
|
68 |
+
f.write(picture.getvalue())
|
69 |
+
else:
|
70 |
+
with r1c2:
|
71 |
+
st.title('Your Data')
|
72 |
+
r2c1,r2c2 = st.columns([2,2])
|
73 |
+
|
74 |
+
with r2c1:
|
75 |
+
st.text_input('Name', '')
|
76 |
+
st.text_input('Address', '')
|
77 |
+
st.text_input('Phone', '')
|
78 |
+
st.text_input('Class', '')
|
79 |
+
st.text_input('Section', '')
|
80 |
+
st.text_input('Roll', '')
|
81 |
+
with r2c2:
|
82 |
+
st.text_input('Code', '')
|
83 |
+
st.text_input('Picture', '')
|
84 |
+
st.text_input('Guardian Number','')
|
85 |
+
st.text_input('Father\'s Name', '')
|
86 |
+
st.text_input('Mother\'s Name', '')
|
87 |
+
st.text_input('Blood Group', '')
|
88 |
+
st.text_input('DOB', str(''))
|
89 |
+
mycode = "<script>alert('No data found for this Section and roll number.')</script>"
|
90 |
+
components.html(mycode, height=0, width=0)
|
91 |
+
else:
|
92 |
+
with r1c2:
|
93 |
+
st.title('Your Data')
|
94 |
+
r2c1,r2c2 = st.columns([2,2])
|
95 |
+
with r2c1:
|
96 |
+
st.text_input('Name', '')
|
97 |
+
st.text_input('Address', '')
|
98 |
+
st.text_input('Phone', '')
|
99 |
+
st.text_input('Class', '')
|
100 |
+
st.text_input('Section', '')
|
101 |
+
st.text_input('Roll', '')
|
102 |
+
with r2c2:
|
103 |
+
st.text_input('Code', '')
|
104 |
+
st.text_input('Picture', '')
|
105 |
+
st.text_input('Guardian Number','')
|
106 |
+
st.text_input('Father\'s Name', '')
|
107 |
+
st.text_input('Mother\'s Name', '')
|
108 |
+
st.text_input('Blood Group', '')
|
109 |
+
st.text_input('DOB', str(''))
|