from config.process_text import DataManager import pandas as pd import streamlit as st from arabic_support import support_arabic_text from pathlib import Path from PIL import Image # مسیر فایل فعلی current_file_path = Path(__file__).resolve() # مسیر ریشه پروژه (یک سطح بالاتر از فایل فعلی) project_root = current_file_path.parents[1] # مسیرهای دایرکتوری‌ها assets_dir = project_root / "asset" database_dir = project_root / "data" styles_dir = project_root / "styles" st.set_page_config( page_title="Data Entry", page_icon="📈", layout="wide", initial_sidebar_state="expanded", ) # پشتیبانی از متن عربی در تمامی اجزاء support_arabic_text(all=True) # خواندن CSS از فایل with open(styles_dir / "main.css", "r") as file: css_code = file.read() # اعمال CSS st.markdown(f"", unsafe_allow_html=True) side = st.sidebar state = st.session_state if "message" not in state: state["message"] = "No changes" with side: img = Image.open(assets_dir / "robot.png") st.image(img, width=250, caption="Enter Data to DB") messageboard = st.empty() group_dict = { "Movement Disorders": "L01", "Chorea in Face, neck, upper limbs, Trunk, lower limbs, and generalized": "L02", "Eye movement disorders and neurological symptoms": "L03", "Neurometabolic Diseases": "L04", "Hyperhomocysteinemia": "L06", "Psychiatric manifestations": "L05", "Spinal cord involvement": "L07", "Intracellular Cobalamin Metabolism": "L08", "Lysosomal acid lipase deficiency": "L09", "Di-hydro Lipoamide Dehydrogenase Deficiency": "L10", "hypophosphatemia": "L11", "Non hepatic hyperammonemic encephalopathy complications following bariatric surgery": "L12", "upper limb tremor": "L13", "mitochondrial diseases": "L14", } def _clear_cache(): for key in st.session_state.keys(): del st.session_state[key] def save_to_db(): return edited_df.to_csv(database_dir / "database.csv", index=False) def _add_db_callback(): datamanager = DataManager() if ( state.options != "" and state.level != "" and state.question_text != "" and state.feedback != "" ): try: group_id = datamanager.get_id(state.group_key) datamanager.save_to_database( state.level, state.question_text, group_id, state.options, state.feedback, ) state["message"] = "saved!" except IndexError as e: st.error(e) st.title("answer") with st.form("answer_form", clear_on_submit=False): col1, col2, col3 = st.columns([4, 1, 1]) with col1: st.selectbox( label="Group name", options=group_dict.keys(), key="group_key" ) # Corrected the key parameter with col2: st.text_input( label="Question id", placeholder="Question id", value=None, key="level", ) with col3: st.text_input( label="next", placeholder="next", value=None, key="next", ) st.text_area( label="Question text", value=None, placeholder="Question text", key="question_text", ) st.text_input( label="Option text", value=None, placeholder="Option text", key="option" ) st.text_input( label="action text", value=None, placeholder="action text", key="feedback" ) submitted = st.form_submit_button( "submitted", on_click=_add_db_callback, ) if submitted: messageboard.info(state.message) with st.expander("show data"): df_db = pd.read_csv(database_dir / "database.csv") edited_df = st.data_editor( df_db, num_rows="dynamic", use_container_width=True, hide_index=True, on_change=save_to_db, ) clear = st.button("Clear Cash", on_click=_clear_cache)