File size: 4,286 Bytes
7615861
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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(''))