Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import os | |
| def load_data(): | |
| if os.path.exists('data.txt'): | |
| with open('data.txt', 'r') as file: | |
| lines = file.readlines() | |
| nombre = lines[0].strip().split(': ')[1] | |
| fecha = lines[1].strip().split(': ')[1] | |
| return nombre, fecha | |
| return '', '' | |
| def save_data(nombre, fecha): | |
| with open('data.txt', 'w') as file: | |
| file.write(f'nombre: {nombre}\n') | |
| file.write(f'fecha: {fecha}\n') | |
| def main(): | |
| st.title('Data Entry Popup') | |
| if 'show_popup' not in st.session_state: | |
| st.session_state.show_popup = False | |
| if st.button('Open Popup'): | |
| st.session_state.show_popup = True | |
| if st.session_state.show_popup: | |
| st.write('### Enter Data') | |
| nombre, fecha = load_data() | |
| new_nombre = st.text_input('Nombre', value=nombre) | |
| new_fecha = st.text_input('Fecha', value=fecha) | |
| if st.button('Save'): | |
| save_data(new_nombre, new_fecha) | |
| st.success('Data saved successfully') | |
| st.session_state.show_popup = False | |
| if st.button('Cancel'): | |
| st.session_state.show_popup = False | |
| if __name__ == "__main__": | |
| main() | |