Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
from datetime import datetime | |
# Function to check user credentials | |
def check_credentials(username, password): | |
return username == "Josia" and password == "admin" | |
# Function to save data to CSV | |
def save_data(form_data, username): | |
# Convert to DataFrame and append to CSV | |
df = pd.DataFrame([form_data]) | |
csv_path = f'collected_data_{username}.csv' | |
df.to_csv(csv_path, mode='a', header=not pd.io.common.file_exists(csv_path), index=False) | |
# Main App | |
def main(): | |
# Page configuration | |
st.set_page_config(page_title="Frijoles", layout="wide") | |
# Sidebar for login | |
st.sidebar.title("Common Bean Data Collection App") | |
st.sidebar.header("Please Log In") | |
username = st.sidebar.text_input("Username") | |
password = st.sidebar.text_input("Password", type="password") | |
if st.sidebar.button("Login"): | |
if check_credentials(username, password): | |
st.session_state['authenticated'] = True | |
else: | |
st.session_state['authenticated'] = False | |
st.sidebar.error("The username or password you entered is incorrect.") | |
if 'authenticated' not in st.session_state: | |
st.session_state['authenticated'] = False | |
# Main Page | |
if st.session_state['authenticated']: | |
st.title('Welcome to Common Bean Data Collection App') | |
# Display info links | |
col1, col2 = st.columns(2) | |
with col1: | |
if st.button('Learn More About Beans'): | |
# Display info about beans or include a link to more information | |
st.write("Information about beans will be displayed here or linked.") | |
with col2: | |
if st.button('Learn More About Breeding'): | |
# Display info about breeding or include a link to more information | |
st.write("Information about breeding will be displayed here or linked.") | |
st.header("Collect new data") | |
with st.form("new_data_form"): | |
# Fields for the collection form | |
disease_type = st.selectbox("Select disease type", ['ALS', 'CBB']) | |
region = st.selectbox("Select region", ['Selian', 'Uyole', 'Maluku']) | |
genotype = st.selectbox("Select genotype", ['Genotype A', 'Genotype B']) | |
growth_level = st.selectbox("Select plant growth level", ['First Trifoliate', 'Second Trifoliate']) | |
plant_number = st.selectbox("Select plant number", list(range(1, 11))) | |
leaf_number = st.selectbox("Select leaf number", list(range(1, 11))) | |
scan_number = st.selectbox("Select scan number", list(range(1, 11))) | |
visual_score = st.slider("Visual Score", 1, 9, 1) | |
# Submit button for form | |
submit_data = st.form_submit_button(label='Submit Data') | |
if submit_data: | |
form_data = { | |
"Disease Type": disease_type, | |
"Region": region, | |
"Genotype": genotype, | |
"Growth Level": growth_level, | |
"Plant Number": plant_number, | |
"Leaf Number": leaf_number, | |
"Scan Number": scan_number, | |
"Visual Score": visual_score, | |
"Username": username, # Include username in the saved data for identification | |
"Date": datetime.now().strftime("%Y-%m-%d"), | |
"Time": datetime.now().strftime("%H:%M:%S"), | |
} | |
# Button to open ScanSpectrum app | |
st.markdown("<a href='scanspectrum://open' target='_blank'><button style='height: 50px; width: 300px; font-size: 20px;'>Open ScanSpectrum App</button></a>", unsafe_allow_html=True) | |
st.write("Please complete the scan and upload the results. After scanning, return here and click 'Save Data'.") | |
# Placeholder for storing scan data | |
scanned_data_placeholder = {'wavelength': [680, 500, 450], 'intensity': [0.8, 0.6, 0.4]} | |
scanned_data = pd.DataFrame(scanned_data_placeholder) # This would actually be fetched from the ScanSpectrum app | |
# Save button to finalize data entry | |
if st.button('Save Data'): | |
save_data(form_data, username) | |
st.success("Data saved successfully.") | |
else: | |
st.warning("You need to login to access the data collection form.") | |
# Run the main app | |
if __name__ == "__main__": | |
main() |