Spaces:
Runtime error
Runtime error
import pandas as pd | |
import streamlit as st | |
import streamlit.components.v1 as components | |
from PIL import Image | |
from io import BytesIO | |
# Load the Excel file | |
st.set_page_config(layout="wide") | |
ipcode="" | |
ipname="" | |
ipsection='' | |
ipclass='' | |
r1c1,_,r1c2 = st.columns([4,0.5,4]) | |
section_set=() | |
with r1c1: | |
st.title('Data Entry') | |
uploaded_file = st.file_uploader("Choose a file", type = 'xlsx') | |
if uploaded_file is not None: | |
df = pd.read_excel(uploaded_file, sheet_name='Sheet1') | |
section_set=tuple(set(list(df['Section']))) | |
r1lc1,r1lc2 = st.columns([2,2]) | |
with r1lc1: | |
Section_name= st.selectbox( "Select Section",section_set) | |
with r1lc2: | |
roll_no = st.text_input('Enter Roll Number') | |
cb0,cb1,cb2,_=st.columns([1,1,1,3]) | |
with cb2: | |
go=st.button('Go') | |
with cb1: | |
next=st.button('Next >') | |
with cb0: | |
prev=st.button('< Prev') | |
picture = st.camera_input("Take a picture") | |
if go or picture: | |
# Filter the dataframe based on the input | |
filtered_df = df[(df['Section'] == Section_name) & (df['Roll'] == int(roll_no))] | |
if not filtered_df.empty: | |
with r1c2: | |
st.title('Your Data') | |
r2c1,r2c2 = st.columns([2,2]) | |
# Display the data in text fields | |
with r2c1: | |
ipname=st.text_input('Name', filtered_df['Name'].values[0]) | |
ipaddress=st.text_input('Address', filtered_df['Address'].values[0]) | |
ipphone=st.text_input('Phone', filtered_df['Phone'].values[0]) | |
ipclass=st.text_input('Class', filtered_df['Class'].values[0]) | |
ipsection=st.text_input('Section', filtered_df['Section'].values[0]) | |
iproll=st.text_input('Roll', filtered_df['Roll'].values[0]) | |
with r2c2: | |
ipcode=st.text_input('Code', filtered_df['Code'].values[0]) | |
ippic=st.text_input('Picture', filtered_df['Picture'].values[0]) | |
ipgurno=st.text_input('Guardian Number', filtered_df['Guardian Number'].values[0]) | |
ipfn=st.text_input('Father\'s Name', filtered_df['Father\'s Name'].values[0]) | |
inmn=st.text_input('Mother\'s Name', filtered_df['Mother\'s Name'].values[0]) | |
inbg=st.text_input('Blood Group', filtered_df['Blood Group'].values[0]) | |
indob=st.text_input('DOB', str(filtered_df['DOB'].values[0])) | |
if picture: | |
df.loc[df.Code == ipcode, 'Picture'] =f"Photo/{ipclass}/{ipsection}/{ipcode}_{ipname}.jpg" | |
with open(f"Photo/{ipclass}/{ipsection}/{ipcode}_{ipname}.jpg", 'wb') as f: | |
f.write(picture.getvalue()) | |
else: | |
with r1c2: | |
st.title('Your Data') | |
r2c1,r2c2 = st.columns([2,2]) | |
with r2c1: | |
st.text_input('Name', '') | |
st.text_input('Address', '') | |
st.text_input('Phone', '') | |
st.text_input('Class', '') | |
st.text_input('Section', '') | |
st.text_input('Roll', '') | |
with r2c2: | |
st.text_input('Code', '') | |
st.text_input('Picture', '') | |
st.text_input('Guardian Number','') | |
st.text_input('Father\'s Name', '') | |
st.text_input('Mother\'s Name', '') | |
st.text_input('Blood Group', '') | |
st.text_input('DOB', str('')) | |
mycode = "<script>alert('No data found for this Section and roll number.')</script>" | |
components.html(mycode, height=0, width=0) | |
else: | |
with r1c2: | |
st.title('Your Data') | |
r2c1,r2c2 = st.columns([2,2]) | |
with r2c1: | |
st.text_input('Name', '') | |
st.text_input('Address', '') | |
st.text_input('Phone', '') | |
st.text_input('Class', '') | |
st.text_input('Section', '') | |
st.text_input('Roll', '') | |
with r2c2: | |
st.text_input('Code', '') | |
st.text_input('Picture', '') | |
st.text_input('Guardian Number','') | |
st.text_input('Father\'s Name', '') | |
st.text_input('Mother\'s Name', '') | |
st.text_input('Blood Group', '') | |
st.text_input('DOB', str('')) | |