import streamlit as st # Conversion factors for various time units TIME_UNITS = { 'Seconds': 1, 'Minutes': 60, 'Hours': 3600, 'Days': 86400, 'Weeks': 604800, 'Months (30 days)': 2592000, 'Years (365 days)': 31536000 } def convert_time(value, from_unit, to_unit): # Convert the input value to seconds value_in_seconds = value * TIME_UNITS[from_unit] # Convert from seconds to the target unit converted_value = value_in_seconds / TIME_UNITS[to_unit] return converted_value def main(): st.title('Time Units Converter') # Input value and select time units value = st.number_input("Enter the value to convert", min_value=0.0, step=0.1) from_unit = st.selectbox("From unit", list(TIME_UNITS.keys())) to_unit = st.selectbox("To unit", list(TIME_UNITS.keys())) if st.button('Convert'): if value >= 0: converted_value = convert_time(value, from_unit, to_unit) st.write(f"{value} {from_unit} = {converted_value:.4f} {to_unit}") else: st.error("Please enter a valid value (greater than or equal to 0).") if __name__ == "__main__": main()