parthasonu505 commited on
Commit
ee222ac
·
verified ·
1 Parent(s): 67930f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -12
app.py CHANGED
@@ -14,6 +14,7 @@ ipsection=''
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:
@@ -31,15 +32,18 @@ with r1c1:
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')
@@ -53,8 +57,13 @@ with r1c1:
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
@@ -78,10 +87,16 @@ if st.session_state.go:
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])
 
 
 
85
  ipgurno=st.text_input('Guardian Number', filtered_df['Guardian Number'].values[0])
86
  ipfn=st.text_input('Father\'s Name', filtered_df['Father\'s Name'].values[0])
87
  inmn=st.text_input('Mother\'s Name', filtered_df['Mother\'s Name'].values[0])
@@ -89,13 +104,12 @@ if st.session_state.go:
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
  print("Picture name: ",ippic)
95
- #session = ftplib.FTP('ftp.digidemy.in','u669719505.partha','Partha123$#@')
96
- # session.set_pasv(True)
97
- # session.storbinary(f'STOR {ippic}', picture)
98
- #session.quit()
99
  # with open(f"Photo/{ipclass}/{ipsection}/{ipcode}_{ipname}.jpg", 'wb') as f:
100
  # f.write(picture.getvalue())
101
  if(submit):
@@ -122,7 +136,7 @@ if st.session_state.go:
122
  # Execute the query
123
  cur.execute(del_query)
124
 
125
- 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}');"""
126
  # Execute the query
127
  cur.execute(insert_query)
128
 
 
14
  ipclass=''
15
  r1c1,_,r1c2 = st.columns([4,0.5,4])
16
  section_set=()
17
+ class_set=()
18
  if 'go' not in st.session_state:
19
  st.session_state.go = False
20
  if 'df' not in st.session_state:
 
32
  print("****************hi*****************")
33
  st.session_state.df = pd.read_excel(uploaded_file, sheet_name='Sheet1')
34
  section_set=tuple(set(list(st.session_state.df['Section'])))
35
+ class_set=tuple(set(list(st.session_state.df['Class'])))
36
  uploaded_file=None
37
 
38
  if 'photo_taken' not in st.session_state.df.columns:
39
  st.session_state.df['photo_taken'] = 'No'
40
  r1lc1,r1lc2 = st.columns([2,2])
41
  with r1lc1:
42
+ class_name=st.selectbox( "Select Class",class_set)
43
  Section_name= st.selectbox( "Select Section",section_set)
44
+
45
  if Section_name is not None:
46
+ temp_name= tuple(set(list(st.session_state.df[(st.session_state.df['Section'] == Section_name)&(st.session_state.df['Class'] == class_name)]["Name"])))
47
  select_name=st.selectbox( "Select Name",temp_name)
48
  with r1lc2:
49
  roll_no = st.text_input('Enter Roll Number')
 
57
  prev=st.button('< Prev')
58
 
59
  if(st.session_state.go):
60
+ option = st.selectbox('How would you like submit photo',('Capture', 'Upload'))
61
+ if(option == 'Capture'):
62
+ picture = st.camera_input("Take a picture")
63
+ else:
64
+ picture = st.file_uploader("Upload a picture", type = 'jpg')
65
+ if picture:
66
+ st.image(picture, caption='Uploaded Photo')
67
 
68
  if st.session_state.go:
69
  # Filter the dataframe based on the input
 
87
  ipclass=st.text_input('Class', filtered_df['Class'].values[0])
88
  ipsection=st.text_input('Section', filtered_df['Section'].values[0])
89
  iproll=st.text_input('Roll', filtered_df['Roll'].values[0])
90
+ if not picture:
91
+ ipphototaken=st.text_input('Photo Taken', filtered_df['photo_taken'].values[0])
92
+ else:
93
+ ipphototaken=st.text_input('Photo Taken', "Yes")
94
  with r2c2:
95
  ipcode=st.text_input('Code', filtered_df['Code'].values[0])
96
+ if picture:
97
+ ippic=st.text_input('Picture', f"{school_name}_{ipclass}_{ipsection}_{ipcode}_{ipname}.jpg")
98
+ else:
99
+ ippic=st.text_input('Picture', filtered_df['Picture'].values[0])
100
  ipgurno=st.text_input('Guardian Number', filtered_df['Guardian Number'].values[0])
101
  ipfn=st.text_input('Father\'s Name', filtered_df['Father\'s Name'].values[0])
102
  inmn=st.text_input('Mother\'s Name', filtered_df['Mother\'s Name'].values[0])
 
104
  indob=st.text_input('DOB', str(filtered_df['DOB'].values[0]))
105
  submit=st.button("submit", type="primary")
106
  if picture:
107
+ st.session_state.df.loc[st.session_state.df.Code == ipcode, 'Picture'] =f"{school_name}_{ipclass}_{ipsection}_{ipcode}_{ipname}.jpg"
108
+ ippic=f"{school_name}_{ipclass}_{ipsection}_{ipcode}_{ipname}.jpg"
109
  print("Picture name: ",ippic)
110
+ session = ftplib.FTP('ftp.digidemy.in','u669719505.partha','Partha123$#@')
111
+ session.storbinary(f'STOR {ippic}', picture)
112
+ session.quit()
 
113
  # with open(f"Photo/{ipclass}/{ipsection}/{ipcode}_{ipname}.jpg", 'wb') as f:
114
  # f.write(picture.getvalue())
115
  if(submit):
 
136
  # Execute the query
137
  cur.execute(del_query)
138
 
139
+ insert_query = f"""INSERT INTO schooltesttable (OrgId,Name, Address, Phone, Class, Section, Roll, photo_taken, Code, Picture, Guardian_Number, Fathers_Name, Mothers_Name, Blood_Group,DOB)VALUES ('{school_name}','{ipname}', '{ipaddress}', '{ipphone}', '{ipclass}', '{ipsection}', '{iproll}', '{ipphototaken}', '{ipcode}', '{ippic}', '{ipgurno}', '{ipfn}', '{inmn}', '{inbg}', '{indob}');"""
140
  # Execute the query
141
  cur.execute(insert_query)
142