main.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. """NEO entrypoint"""
  2. from datetime import datetime
  3. import streamlit as st
  4. from db.models import subject
  5. from components.remove_style import hide_footer
  6. def _set_main_page_config():
  7. # set_page_config must be the first command,
  8. # and must only be set once per page.
  9. st.set_page_config(
  10. page_title="NEO",
  11. page_icon=":house:",
  12. )
  13. hide_footer()
  14. def _create_subject(conn):
  15. with st.form("subject_form"):
  16. st.write("创建用户")
  17. name = st.text_input("姓名")
  18. gender = st.radio("性别", ["男", "女"])
  19. birthday = st.date_input("生日")
  20. submitted = st.form_submit_button("确定")
  21. if submitted:
  22. create_time = datetime.strptime(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S")
  23. sub_new = {"name": name, "gender": gender, "birthday": birthday, "create_time": create_time}
  24. subject.create_subject(conn, sub_new)
  25. def _main_page_content():
  26. st.write("# NEO! 👋")
  27. conn = st.connection("sql_app", type="sql")
  28. subject.create_table(conn)
  29. _create_subject(conn)
  30. subjects = subject.get_subjects(conn)
  31. st.write("# 用户列表")
  32. st.dataframe(subjects)
  33. st.markdown(
  34. """
  35. ### 更多信息
  36. - 点击查看 [Neuracle](http://www.neuracle.cn)
  37. """
  38. )
  39. st.markdown(
  40. """
  41. 版权所有 © 博睿康科技(常州)股份有限公司
  42. """
  43. )
  44. def start_app():
  45. _set_main_page_config()
  46. _main_page_content()
  47. return True
  48. start_app()