Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 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):
|
|
@@ -8,17 +10,19 @@ def check_credentials(username, password):
|
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|
|
@@ -35,24 +39,13 @@ def main():
|
|
| 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 |
-
#
|
| 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'])
|
|
@@ -61,37 +54,42 @@ def main():
|
|
| 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 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 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 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
st.
|
| 95 |
|
| 96 |
else:
|
| 97 |
st.warning("You need to login to access the data collection form.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
from datetime import datetime
|
| 4 |
+
import glob
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
# Function to check user credentials
|
| 8 |
def check_credentials(username, password):
|
|
|
|
| 10 |
|
| 11 |
# Function to save data to CSV
|
| 12 |
def save_data(form_data, username):
|
| 13 |
+
# Convert to DataFrame and append to CSV. Here we assume that all CSV files are stored in the current directory.
|
| 14 |
df = pd.DataFrame([form_data])
|
| 15 |
csv_path = f'collected_data_{username}.csv'
|
| 16 |
+
df.to_csv(csv_path, mode='a', header=not os.path.exists(csv_path), index=False)
|
| 17 |
+
|
| 18 |
+
# Function to list all CSV files created by the users
|
| 19 |
+
def list_csv_files():
|
| 20 |
+
# List all CSV files in the current directory
|
| 21 |
+
return glob.glob('collected_data_*.csv')
|
| 22 |
|
| 23 |
# Main App
|
| 24 |
def main():
|
|
|
|
| 25 |
st.set_page_config(page_title="Frijoles", layout="wide")
|
|
|
|
|
|
|
| 26 |
st.sidebar.title("Common Bean Data Collection App")
|
| 27 |
st.sidebar.header("Please Log In")
|
| 28 |
|
|
|
|
| 39 |
if 'authenticated' not in st.session_state:
|
| 40 |
st.session_state['authenticated'] = False
|
| 41 |
|
|
|
|
| 42 |
if st.session_state['authenticated']:
|
| 43 |
st.title('Welcome to Common Bean Data Collection App')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
# Form for new data collection
|
| 46 |
st.header("Collect new data")
|
| 47 |
with st.form("new_data_form"):
|
| 48 |
+
# Collect necessary information from user
|
| 49 |
disease_type = st.selectbox("Select disease type", ['ALS', 'CBB'])
|
| 50 |
region = st.selectbox("Select region", ['Selian', 'Uyole', 'Maluku'])
|
| 51 |
genotype = st.selectbox("Select genotype", ['Genotype A', 'Genotype B'])
|
|
|
|
| 54 |
leaf_number = st.selectbox("Select leaf number", list(range(1, 11)))
|
| 55 |
scan_number = st.selectbox("Select scan number", list(range(1, 11)))
|
| 56 |
visual_score = st.slider("Visual Score", 1, 9, 1)
|
| 57 |
+
|
| 58 |
+
submitted = st.form_submit_button("Save")
|
| 59 |
|
| 60 |
+
if submitted:
|
| 61 |
+
# Construct the form data to save
|
| 62 |
+
form_data = {
|
| 63 |
+
"Date": datetime.now().strftime("%Y-%m-%d"),
|
| 64 |
+
"Time": datetime.now().strftime("%H:%M:%S"),
|
| 65 |
+
"Disease Type": disease_type,
|
| 66 |
+
"Region": region,
|
| 67 |
+
"Genotype": genotype,
|
| 68 |
+
"Growth Level": growth_level,
|
| 69 |
+
"Plant Number": plant_number,
|
| 70 |
+
"Leaf Number": leaf_number,
|
| 71 |
+
"Scan Number": scan_number,
|
| 72 |
+
"Visual Score": visual_score
|
| 73 |
+
}
|
| 74 |
+
save_data(form_data, username)
|
| 75 |
+
st.success("Data saved successfully!")
|
| 76 |
|
| 77 |
+
# Button to open ScanSpectrum app (Placeholder for actual URL scheme)
|
| 78 |
+
st.markdown("Please use your mobile device to open the ScanSpectrum app and perform the scan.")
|
| 79 |
+
st.markdown("<a href='scanspectrum://'><button style='height: 50px; width: 300px; font-size: 20px;'>Open ScanSpectrum App</button></a>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
+
# Functionality to preview CSV files
|
| 82 |
+
st.header("Preview Saved Data")
|
| 83 |
+
all_csv_files = list_csv_files()
|
| 84 |
+
selected_csv = st.selectbox("Select a CSV file to preview", all_csv_files)
|
| 85 |
+
|
| 86 |
+
if st.button('Show Selected CSV'):
|
| 87 |
+
if selected_csv:
|
| 88 |
+
data_to_show = pd.read_csv(selected_csv)
|
| 89 |
+
st.write(f"Preview of {selected_csv}:")
|
| 90 |
+
st.dataframe(data_to_show)
|
| 91 |
+
else:
|
| 92 |
+
st.error("No CSV file selected.")
|
| 93 |
|
| 94 |
else:
|
| 95 |
st.warning("You need to login to access the data collection form.")
|