Spaces:
Sleeping
Sleeping
Rename scanapp to scanapp.py
Browse files- scanapp +0 -0
- scanapp.py +101 -0
scanapp
DELETED
|
File without changes
|
scanapp.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
|
| 5 |
+
# Function to check user credentials
|
| 6 |
+
def check_credentials(username, password):
|
| 7 |
+
return username == "Josia" and password == "admin"
|
| 8 |
+
|
| 9 |
+
# Function to save data to CSV
|
| 10 |
+
def save_data(form_data, username):
|
| 11 |
+
# Convert to DataFrame and append to CSV
|
| 12 |
+
df = pd.DataFrame([form_data])
|
| 13 |
+
csv_path = f'collected_data_{username}.csv'
|
| 14 |
+
df.to_csv(csv_path, mode='a', header=not pd.io.common.file_exists(csv_path), index=False)
|
| 15 |
+
|
| 16 |
+
# Main App
|
| 17 |
+
def main():
|
| 18 |
+
# Page configuration
|
| 19 |
+
st.set_page_config(page_title="Frijoles", layout="wide")
|
| 20 |
+
|
| 21 |
+
# Sidebar for login
|
| 22 |
+
st.sidebar.title("Common Bean Data Collection App")
|
| 23 |
+
st.sidebar.header("Please Log In")
|
| 24 |
+
|
| 25 |
+
username = st.sidebar.text_input("Username")
|
| 26 |
+
password = st.sidebar.text_input("Password", type="password")
|
| 27 |
+
|
| 28 |
+
if st.sidebar.button("Login"):
|
| 29 |
+
if check_credentials(username, password):
|
| 30 |
+
st.session_state['authenticated'] = True
|
| 31 |
+
else:
|
| 32 |
+
st.session_state['authenticated'] = False
|
| 33 |
+
st.sidebar.error("The username or password you entered is incorrect.")
|
| 34 |
+
|
| 35 |
+
if 'authenticated' not in st.session_state:
|
| 36 |
+
st.session_state['authenticated'] = False
|
| 37 |
+
|
| 38 |
+
# Main Page
|
| 39 |
+
if st.session_state['authenticated']:
|
| 40 |
+
st.title('Welcome to Common Bean Data Collection App')
|
| 41 |
+
|
| 42 |
+
# Display info links
|
| 43 |
+
col1, col2 = st.columns(2)
|
| 44 |
+
with col1:
|
| 45 |
+
if st.button('Learn More About Beans'):
|
| 46 |
+
# Display info about beans or include a link to more information
|
| 47 |
+
st.write("Information about beans will be displayed here or linked.")
|
| 48 |
+
with col2:
|
| 49 |
+
if st.button('Learn More About Breeding'):
|
| 50 |
+
# Display info about breeding or include a link to more information
|
| 51 |
+
st.write("Information about breeding will be displayed here or linked.")
|
| 52 |
+
|
| 53 |
+
st.header("Collect new data")
|
| 54 |
+
with st.form("new_data_form"):
|
| 55 |
+
# Fields for the collection form
|
| 56 |
+
disease_type = st.selectbox("Select disease type", ['ALS', 'CBB'])
|
| 57 |
+
region = st.selectbox("Select region", ['Selian', 'Uyole', 'Maluku'])
|
| 58 |
+
genotype = st.selectbox("Select genotype", ['Genotype A', 'Genotype B'])
|
| 59 |
+
growth_level = st.selectbox("Select plant growth level", ['First Trifoliate', 'Second Trifoliate'])
|
| 60 |
+
plant_number = st.selectbox("Select plant number", list(range(1, 11)))
|
| 61 |
+
leaf_number = st.selectbox("Select leaf number", list(range(1, 11)))
|
| 62 |
+
scan_number = st.selectbox("Select scan number", list(range(1, 11)))
|
| 63 |
+
visual_score = st.slider("Visual Score", 1, 9, 1)
|
| 64 |
+
|
| 65 |
+
# Submit button for form
|
| 66 |
+
submit_data = st.form_submit_button(label='Submit Data')
|
| 67 |
+
|
| 68 |
+
if submit_data:
|
| 69 |
+
form_data = {
|
| 70 |
+
"Disease Type": disease_type,
|
| 71 |
+
"Region": region,
|
| 72 |
+
"Genotype": genotype,
|
| 73 |
+
"Growth Level": growth_level,
|
| 74 |
+
"Plant Number": plant_number,
|
| 75 |
+
"Leaf Number": leaf_number,
|
| 76 |
+
"Scan Number": scan_number,
|
| 77 |
+
"Visual Score": visual_score,
|
| 78 |
+
"Username": username, # Include username in the saved data for identification
|
| 79 |
+
"Date": datetime.now().strftime("%Y-%m-%d"),
|
| 80 |
+
"Time": datetime.now().strftime("%H:%M:%S"),
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
# Button to open ScanSpectrum app
|
| 84 |
+
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)
|
| 85 |
+
st.write("Please complete the scan and upload the results. After scanning, return here and click 'Save Data'.")
|
| 86 |
+
|
| 87 |
+
# Placeholder for storing scan data
|
| 88 |
+
scanned_data_placeholder = {'wavelength': [680, 500, 450], 'intensity': [0.8, 0.6, 0.4]}
|
| 89 |
+
scanned_data = pd.DataFrame(scanned_data_placeholder) # This would actually be fetched from the ScanSpectrum app
|
| 90 |
+
|
| 91 |
+
# Save button to finalize data entry
|
| 92 |
+
if st.button('Save Data'):
|
| 93 |
+
save_data(form_data, username)
|
| 94 |
+
st.success("Data saved successfully.")
|
| 95 |
+
|
| 96 |
+
else:
|
| 97 |
+
st.warning("You need to login to access the data collection form.")
|
| 98 |
+
|
| 99 |
+
# Run the main app
|
| 100 |
+
if __name__ == "__main__":
|
| 101 |
+
main()
|