parthasonu505 commited on
Commit
d864083
·
verified ·
1 Parent(s): d569428

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -15
app.py CHANGED
@@ -3,7 +3,7 @@ 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")
@@ -14,33 +14,58 @@ 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')
@@ -53,6 +78,7 @@ if go or picture:
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])
@@ -61,11 +87,46 @@ if go or picture:
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')
@@ -78,6 +139,7 @@ if go or picture:
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', '')
@@ -86,8 +148,7 @@ if go or picture:
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')
@@ -99,6 +160,7 @@ else:
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', '')
@@ -106,4 +168,4 @@ else:
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(''))
 
3
  import streamlit.components.v1 as components
4
  from PIL import Image
5
  from io import BytesIO
6
+ import mysql.connector
7
 
8
  # Load the Excel file
9
  st.set_page_config(layout="wide")
 
14
  ipclass=''
15
  r1c1,_,r1c2 = st.columns([4,0.5,4])
16
  section_set=()
17
+ if 'go' not in st.session_state:
18
+ st.session_state.go = False
19
+ if 'df' not in st.session_state:
20
+ st.session_state.df = None
21
+ def change_go():
22
+ st.session_state.go = True
23
+
24
  with r1c1:
25
  st.title('Data Entry')
26
+ school_name = st.text_input("Please Enter The School Code", "12345")
27
  uploaded_file = st.file_uploader("Choose a file", type = 'xlsx')
28
+
29
  if uploaded_file is not None:
30
+ if st.session_state.df is None:
31
+ print("****************hi*****************")
32
+ st.session_state.df = pd.read_excel(uploaded_file, sheet_name='Sheet1')
33
+ section_set=tuple(set(list(st.session_state.df['Section'])))
34
+ uploaded_file=None
35
+
36
+ if 'photo_taken' not in st.session_state.df.columns:
37
+ st.session_state.df['photo_taken'] = 'No'
38
  r1lc1,r1lc2 = st.columns([2,2])
39
  with r1lc1:
40
  Section_name= st.selectbox( "Select Section",section_set)
41
+ if Section_name is not None:
42
+ temp_name= tuple(set(list(st.session_state.df[(st.session_state.df['Section'] == Section_name)]["Name"])))
43
+ select_name=st.selectbox( "Select Name",temp_name)
44
  with r1lc2:
45
  roll_no = st.text_input('Enter Roll Number')
46
+
47
  cb0,cb1,cb2,_=st.columns([1,1,1,3])
48
  with cb2:
49
+ st.button('Go', on_click=change_go)
50
  with cb1:
51
  next=st.button('Next >')
52
  with cb0:
53
  prev=st.button('< Prev')
54
 
55
+ if(st.session_state.go):
56
+ picture = st.camera_input("Take a picture")
57
 
58
+
59
+ if st.session_state.go:
 
60
  # Filter the dataframe based on the input
61
+ if(len(roll_no)):
62
+
63
+ filtered_df = st.session_state.df[(st.session_state.df['Section'] == Section_name) & (st.session_state.df['Roll'] == int(roll_no))]
64
+ index=st.session_state.df.index[(st.session_state.df['Section'] == Section_name) & (st.session_state.df['Roll'] == int(roll_no))].tolist()
65
+ else:
66
+ filtered_df = st.session_state.df[(st.session_state.df['Section'] == Section_name) & (st.session_state.df['Name'] == select_name)]
67
+ index=st.session_state.df.index[(st.session_state.df['Section'] == Section_name) & (st.session_state.df['Name'] == select_name)].tolist()
68
+
69
  if not filtered_df.empty:
70
  with r1c2:
71
  st.title('Your Data')
 
78
  ipclass=st.text_input('Class', filtered_df['Class'].values[0])
79
  ipsection=st.text_input('Section', filtered_df['Section'].values[0])
80
  iproll=st.text_input('Roll', filtered_df['Roll'].values[0])
81
+ ipphototaken=st.text_input('Photo Taken', filtered_df['photo_taken'].values[0])
82
  with r2c2:
83
  ipcode=st.text_input('Code', filtered_df['Code'].values[0])
84
  ippic=st.text_input('Picture', filtered_df['Picture'].values[0])
 
87
  inmn=st.text_input('Mother\'s Name', filtered_df['Mother\'s Name'].values[0])
88
  inbg=st.text_input('Blood Group', filtered_df['Blood Group'].values[0])
89
  indob=st.text_input('DOB', str(filtered_df['DOB'].values[0]))
90
+ submit=st.button("submit", type="primary")
91
  if picture:
92
+ st.session_state.df.loc[st.session_state.df.Code == ipcode, 'Picture'] =f"Photo/{ipclass}/{ipsection}/{ipcode}_{ipname}.jpg"
93
+ ippic=f"Photo/{ipclass}/{ipsection}/{ipcode}_{ipname}.jpg"
94
  with open(f"Photo/{ipclass}/{ipsection}/{ipcode}_{ipname}.jpg", 'wb') as f:
95
  f.write(picture.getvalue())
96
+ if(submit):
97
+ st.session_state.df['Name'][index]=ipname
98
+ st.session_state.df['Address'][index]=ipaddress
99
+ st.session_state.df['Phone'][index]=ipphone
100
+ st.session_state.df['Class'][index]=ipclass
101
+ st.session_state.df['Section'][index]=ipsection
102
+ st.session_state.df['Roll'][index]=iproll
103
+ st.session_state.df['photo_taken'][index]=ipphototaken
104
+ st.session_state.df['Code'][index]=ipcode
105
+ st.session_state.df['Picture'][index]=ippic
106
+ st.session_state.df['Guardian Number'][index]=ipgurno
107
+ st.session_state.df['Father\'s Name'][index]=ipfn
108
+ st.session_state.df['Mother\'s Name'][index]=inmn
109
+ st.session_state.df['Blood Group'][index]=inbg
110
+ st.session_state.df['DOB'][index]=indob
111
+ st.session_state.df.to_excel(f"Data/temp/{school_name}_{ipclass}_data.xlsx")
112
+ #df = pd.read_excel(f"Data/temp/{school_name}_{ipclass}_data.xlsx", sheet_name='Sheet1')
113
+
114
+ myconn = mysql.connector.connect(host = "193.203.184.80", user = "u669719505_school",passwd = "+=I^|BhLc7D", database = "u669719505_school")
115
+ cur = myconn.cursor()
116
+ del_query = f"""DELETE FROM schooltest WHERE Code ='{ipcode}';"""
117
+ # Execute the query
118
+ cur.execute(del_query)
119
+
120
+ insert_query = f"""INSERT INTO schooltest (Name, Address, Phone, Class, Section, Roll, photo_taken, Code, Picture, Guardian_Number, Fathers_Name, Mothers_Name, Blood_Group,DOB)VALUES ('{ipname}', '{ipaddress}', '{ipphone}', '{ipclass}', '{ipsection}', '{iproll}', '{ipphototaken}', '{ipcode}', '{ippic}', '{ipgurno}', '{ipfn}', '{inmn}', '{inbg}', '{indob}');"""
121
+ # Execute the query
122
+ cur.execute(insert_query)
123
+
124
+ # Commit the transaction
125
+ myconn.commit()
126
+ cur.close()
127
+ st.success('Data Is Successfully Updated', icon="✅")
128
+ st.session_state.go=False
129
+
130
  else:
131
  with r1c2:
132
  st.title('Your Data')
 
139
  st.text_input('Class', '')
140
  st.text_input('Section', '')
141
  st.text_input('Roll', '')
142
+ st.text_input('Photo Taken', '')
143
  with r2c2:
144
  st.text_input('Code', '')
145
  st.text_input('Picture', '')
 
148
  st.text_input('Mother\'s Name', '')
149
  st.text_input('Blood Group', '')
150
  st.text_input('DOB', str(''))
151
+ st.success('No Data Found', icon="❌")
 
152
  else:
153
  with r1c2:
154
  st.title('Your Data')
 
160
  st.text_input('Class', '')
161
  st.text_input('Section', '')
162
  st.text_input('Roll', '')
163
+ st.text_input('Photo Taken', '')
164
  with r2c2:
165
  st.text_input('Code', '')
166
  st.text_input('Picture', '')
 
168
  st.text_input('Father\'s Name', '')
169
  st.text_input('Mother\'s Name', '')
170
  st.text_input('Blood Group', '')
171
+ st.text_input('DOB', str(''))