digitalai commited on
Commit
e136565
1 Parent(s): f5eb4e1

Upload 49 files

Browse files
.secrets/secret.yaml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ credentials:
2
+ usernames:
3
+ jsmith:
4
+ email: admin@farz1.com
5
+ name: farz yek
6
+ password: abc # To be replaced with hashed password
7
+ rbriggs:
8
+ email: rbriggs@gmail.com
9
+ name: Rebecca Briggs
10
+ password: def # To be replaced with hashed password
11
+ cookie:
12
+ expiry_days: 30
13
+ key: random_signature_key # Must be string
14
+ name: random_cookie_name
15
+ preauthorized:
16
+ emails:
17
+ - melsby@gmail.com
.streamlit/config.toml CHANGED
@@ -1,4 +1,6 @@
1
  [theme]
2
  backgroundColor="#070e1c"
3
  secondaryBackgroundColor="#1c223f"
4
- textColor="#ffffff"
 
 
 
1
  [theme]
2
  backgroundColor="#070e1c"
3
  secondaryBackgroundColor="#1c223f"
4
+ textColor="#ffffff"
5
+ [client]
6
+ showSidebarNavigation = false
config/__pycache__/conf.cpython-310.pyc CHANGED
Binary files a/config/__pycache__/conf.cpython-310.pyc and b/config/__pycache__/conf.cpython-310.pyc differ
 
config/__pycache__/print_data.cpython-310.pyc CHANGED
Binary files a/config/__pycache__/print_data.cpython-310.pyc and b/config/__pycache__/print_data.cpython-310.pyc differ
 
config/__pycache__/valid_text.cpython-310.pyc CHANGED
Binary files a/config/__pycache__/valid_text.cpython-310.pyc and b/config/__pycache__/valid_text.cpython-310.pyc differ
 
main.py CHANGED
@@ -1,21 +1,10 @@
1
- import time
2
  import streamlit as st
3
- from config.quiz import Question
4
- from config.option import Option
5
- from config.valid_text import is_valid_input, levels
6
- from streamlit_option_menu import option_menu
7
  from arabic_support import support_arabic_text
8
  from pathlib import Path
9
- import json
10
- from PIL import Image
11
- from config.conf import *
12
 
13
- st.set_page_config(
14
- page_title="AI-Medical Questionnaire",
15
- page_icon="💊",
16
- layout="wide",
17
- initial_sidebar_state="expanded",
18
- )
19
 
20
  # مسیر فایل فعلی
21
  current_file_path = Path(__file__).resolve()
@@ -23,11 +12,8 @@ current_file_path = Path(__file__).resolve()
23
  project_root = current_file_path.parents[0]
24
  # مسیرهای دایرکتوری‌ها
25
  assets_dir = project_root / "asset"
26
- database_dir = project_root / "data"
27
  styles_dir = project_root / "styles"
28
-
29
- # پشتیبانی از متن عربی در تمامی اجزاء
30
- support_arabic_text(all=True)
31
 
32
  # خواندن فایل CSS
33
  css_file_path = styles_dir / "main.css"
@@ -36,134 +22,22 @@ with open(css_file_path, "r", encoding="utf-8") as file:
36
 
37
  # اعمال CSS
38
  st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
39
- # def go_to_level(selected):
40
- # state.level = levels()
41
- support_arabic_text(all=True)
42
- state = st.session_state
43
- st.title("AI-Medical Questionnaire")
44
- side = st.sidebar
45
-
46
- if "messages" not in state:
47
- state["messages"] = []
48
- start = """ سلام من دستیار شما هستم. برای بررسی و تصمیم گیری وضعیت بیماران مرحله به مرحله بررسی وضعیت بیمار را با کمک من انجام دهید. برای پیشنهاد می کنم
49
- اختلالات حرکتی را بررسی کنید. آیا بیمار دارای چنین اختلالی است؟)"""
50
- state.messages.append({"role": "assistant", "content": start})
51
- # st.chat_message("user", avatar=str(assets_dir / "user.png")).markdown(
52
- # state["messages"] = []
53
- if "result" not in state:
54
- state.result = ""
55
- if "level" not in state:
56
- state.level = "L01"
57
- state.next = ""
58
- state.previous = ""
59
-
60
- # مسیرهای فایل‌های JSON
61
- question_file = database_dir / "question_data.json"
62
- option_file = database_dir / "option_data.json"
63
-
64
- # ایجاد کلاس‌های سوالات و گزینه‌ها
65
- question_class = Question(question_file, option_file)
66
- option_class = Option(question_file, option_file)
67
-
68
- # بارگذاری داده‌ها
69
- question = question_class.load_question_data()
70
- options = option_class.load_option_data()
71
- question_text = question_class.get_question_text(state.level)
72
-
73
- with side:
74
- img = Image.open(assets_dir / "logo.png")
75
- st.image(
76
- img,
77
- width=250,
78
- caption="جهت بازنشانی از دکمه ریست استفاده کنید",
79
- )
80
-
81
- if st.button("reset"):
82
-
83
- del state["messages"]
84
- st.rerun()
85
-
86
- def response_generator(resp):
87
- yield f"checkpoint: {state.previous}"
88
- yield "\n\n"
89
- for word in resp.split():
90
- character = ""
91
- for char in word:
92
- yield character + char
93
- time.sleep(0.03)
94
- yield " "
95
- time.sleep(0.05)
96
-
97
 
98
- for messages in state.messages:
99
-
100
- if messages["role"] == "assistant":
101
- avatar = str(assets_dir / "robot_icon.png")
102
- elif messages["role"] == "user":
103
- avatar = str(assets_dir / "user.png")
104
- else:
105
- avatar = None # Default
106
-
107
- with st.chat_message(messages["role"], avatar=avatar):
108
- st.markdown(messages["content"])
109
-
110
-
111
- prompt = st.chat_input("""نوشتن پیام""")
112
-
113
- if prompt:
114
- answer = prompt
115
- answer = get_response(answer)
116
- if answer == "L99":
117
- state.result = "L99"
118
-
119
- feedback = option_class.get_feedback("نتیجه", state.result)
120
- st.switch_page("pages/result.py")
121
- st.chat_message("user", avatar=str(assets_dir / "user.png")).markdown(prompt)
122
- state.messages.append({"role": "user", "content": prompt})
123
-
124
- if answer == "بله" or answer == "خیر":
125
-
126
- next_level = option_class.get_next_level(answer, state.level)
127
- feedback = option_class.get_feedback(answer, state.level)
128
-
129
- if next_level != "L98" and next_level != "L99":
130
- my_bar = st.progress(0, text=feedback)
131
- for percent_complete in range(100):
132
- time.sleep(0.01)
133
- my_bar.progress(percent_complete + 1, text=feedback)
134
- time.sleep(1)
135
- my_bar.empty()
136
- state.previous = state.level
137
- state.level = next_level
138
-
139
- resp = question_class.get_question_text(state.level)[0]
140
- with st.chat_message("assistant"):
141
- response = st.write_stream(response_generator(resp))
142
- state.messages.append({"role": "assistant", "content": response})
143
-
144
- elif next_level == "L98":
145
- state.previous = state.level
146
- state.level = next_level
147
 
148
- state.result = feedback
149
- st.switch_page("pages/result.py")
150
- elif next_level == "L99":
151
- state.result = feedback
152
- st.switch_page("pages/result.py")
153
 
154
- elif answer[0] == "L":
155
 
156
- feedback = "تغییر بخش مورد بررسی, تا چند لحظه دیگر"
157
- state.previous = state.level
158
- next_level = answer
159
- state.level = next_level
160
- resp = question_class.get_question_text(state.level)[0]
161
- with st.chat_message("assistant"):
162
- response = st.write_stream(response_generator(resp))
163
- state.messages.append({"role": "assistant", "content": response})
164
 
 
 
 
 
 
 
165
  else:
166
- with st.chat_message("assistant"):
167
- answer = unknown()
168
- response = st.write_stream(response_generator(answer))
169
- state.messages.append({"role": "assistant", "content": response})
 
1
+ from time import sleep
2
  import streamlit as st
 
 
 
 
3
  from arabic_support import support_arabic_text
4
  from pathlib import Path
5
+ from navigation import make_sidebar
 
 
6
 
7
+ support_arabic_text(all=True)
 
 
 
 
 
8
 
9
  # مسیر فایل فعلی
10
  current_file_path = Path(__file__).resolve()
 
12
  project_root = current_file_path.parents[0]
13
  # مسیرهای دایرکتوری‌ها
14
  assets_dir = project_root / "asset"
 
15
  styles_dir = project_root / "styles"
16
+ pages = project_root / "pages"
 
 
17
 
18
  # خواندن فایل CSS
19
  css_file_path = styles_dir / "main.css"
 
22
 
23
  # اعمال CSS
24
  st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
+ state = st.session_state
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
+ make_sidebar()
29
+ st.title("Welcome to AI-Medical Questionnaire")
 
 
 
30
 
31
+ st.write("Please log in to continue (username `admin`, password `admin`).")
32
 
33
+ username = st.text_input("Username")
34
+ password = st.text_input("Password", type="password")
 
 
 
 
 
 
35
 
36
+ if st.button("Log in", type="primary"):
37
+ if username == "admin" and password == "admin":
38
+ state.logged_in = True
39
+ st.success("Logged in successfully!")
40
+ # sleep(0.5)
41
+ st.switch_page(str(pages / "1_app.py"))
42
  else:
43
+ st.error("Incorrect username or password")
 
 
 
navigation.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from time import sleep
3
+ from streamlit.runtime.scriptrunner import get_script_run_ctx
4
+ from streamlit.source_util import get_pages
5
+ from pathlib import Path
6
+ from arabic_support import support_arabic_text
7
+ # مسیر فایل فعلی
8
+ current_file_path = Path(__file__).resolve()
9
+ # مسیر ریشه پروژه (دو سطح بالاتر از فایل فعلی)
10
+ project_root = current_file_path.parents[0]
11
+ # مسیرهای دایرکتوری‌ها
12
+ assets_dir = project_root / "asset"
13
+
14
+ styles_dir = project_root / "styles"
15
+ support_arabic_text(all=True)
16
+
17
+ # خواندن فایل CSS
18
+ css_file_path = styles_dir / "main.css"
19
+
20
+
21
+
22
+ state = st.session_state
23
+ def get_current_page_name():
24
+ ctx = get_script_run_ctx()
25
+ if ctx is None:
26
+ raise RuntimeError("Couldn't get script context")
27
+
28
+ pages = get_pages("")
29
+
30
+ return pages[ctx.page_script_hash]["page_name"]
31
+
32
+
33
+ def make_sidebar():
34
+ support_arabic_text(all=True)
35
+ with open(css_file_path, "r", encoding="utf-8") as file:
36
+ css_code = file.read()
37
+
38
+ # اعمال CSS
39
+ st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
40
+ with st.sidebar:
41
+
42
+ st.title("💊 AI-Medical Questionnaire")
43
+ st.write("")
44
+ st.write("")
45
+
46
+ if state.get("logged_in", False):
47
+ st.page_link("pages/1_app.py", label="دستیار هوشمند", icon="💊")
48
+ st.page_link("pages/2_result.py", label="نتیجه بررسی", icon="💉")
49
+ st.page_link("pages/3_data_entry.py", label="فرم ورود اطلاعات پایگاه داده", icon="✅")
50
+ st.page_link("pages/4_About_us.py", label="درباره سازندگان", icon="🕵️")
51
+ st.page_link("pages/5_print_data.py", label="دریافت گزارش بررسی انجام گرفته", icon="📈")
52
+ st.page_link("pages/6_upload_to_db.py", label="ورود اطلاعات به پایگاه داده", icon="📝")
53
+
54
+ st.write("")
55
+ st.write("")
56
+
57
+ if st.button("Log out"):
58
+ logout()
59
+
60
+ elif get_current_page_name() != "main":
61
+ # If anyone tries to access a secret page without being logged in,
62
+ # redirect them to the login page
63
+ st.switch_page("main.py")
64
+
65
+
66
+
67
+ def logout():
68
+ state.logged_in = False
69
+ st.info("Logged out successfully!")
70
+ sleep(0.5)
71
+ st.switch_page("main.py")
pages/1_app.py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ import streamlit as st
3
+ from config.quiz import Question
4
+ from config.option import Option
5
+ from config.valid_text import is_valid_input, levels
6
+ from arabic_support import support_arabic_text
7
+ from pathlib import Path
8
+ import json
9
+ from PIL import Image
10
+ from config.conf import *
11
+ from navigation import make_sidebar
12
+
13
+
14
+
15
+
16
+ # st.set_page_config(
17
+ # page_title="AI-Medical Questionnaire",
18
+ # page_icon="💊",
19
+ # layout="wide",
20
+ # initial_sidebar_state="expanded",
21
+ # )
22
+
23
+ # مسیر فایل فعلی
24
+ current_file_path = Path(__file__).resolve()
25
+ # مسیر ریشه پروژه (دو سطح بالاتر از فایل فعلی)
26
+ project_root = current_file_path.parents[1]
27
+ # مسیرهای دایرکتوری‌ها
28
+ assets_dir = project_root / "asset"
29
+ database_dir = project_root / "data"
30
+ styles_dir = project_root / "styles"
31
+
32
+ # خواندن فایل CSS
33
+ css_file_path = styles_dir / "main.css"
34
+ with open(css_file_path, "r", encoding="utf-8") as file:
35
+ css_code = file.read()
36
+
37
+ # اعمال CSS
38
+ st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
39
+ # def go_to_level(selected):
40
+ # state.level = levels()
41
+ support_arabic_text(all=True)
42
+ state = st.session_state
43
+ st.title("AI-Medical Questionnaire")
44
+ side = st.sidebar
45
+ make_sidebar()
46
+ if "messages" not in state:
47
+ state["messages"] = []
48
+ start = """ سلام من دستیار شما هستم. برای بررسی و تصمیم گیری وضعیت بیماران مرحله به مرحله بررسی وضعیت بیمار را با کمک من انجام دهید. برای پیشنهاد می کنم
49
+ اختلالات حرکتی را بررسی کنید. آیا بیمار دارای چنین اختلالی است؟)"""
50
+ state.messages.append({"role": "assistant", "content": start})
51
+ # st.chat_message("user", avatar=str(assets_dir / "user.png")).markdown(
52
+ # state["messages"] = []
53
+ if "result" not in state:
54
+ state.result = ""
55
+ if "level" not in state:
56
+ state.level = "L01"
57
+ state.next = ""
58
+ state.previous = ""
59
+
60
+ # مسیرهای فایل‌های JSON
61
+ question_file = database_dir / "question_data.json"
62
+ option_file = database_dir / "option_data.json"
63
+
64
+ # ایجاد کلاس‌های سوالات و گزینه‌ها
65
+ question_class = Question(question_file, option_file)
66
+ option_class = Option(question_file, option_file)
67
+
68
+ # بارگذاری داده‌ها
69
+ question = question_class.load_question_data()
70
+ options = option_class.load_option_data()
71
+ question_text = question_class.get_question_text(state.level)
72
+
73
+ with side:
74
+ img = Image.open(assets_dir / "logo.png")
75
+ st.image(
76
+ img,
77
+ width=250,
78
+ caption="جهت بازنشانی از دکمه ریست استفاده کنید",
79
+ )
80
+
81
+ if st.button("reset"):
82
+
83
+ del state["messages"]
84
+ st.rerun()
85
+
86
+ def response_generator(resp):
87
+ yield f"checkpoint: {state.previous}"
88
+ yield "\n\n"
89
+ for word in resp.split():
90
+ character = ""
91
+ for char in word:
92
+ yield character + char
93
+ time.sleep(0.03)
94
+ yield " "
95
+ time.sleep(0.05)
96
+
97
+
98
+ for messages in state.messages:
99
+
100
+ if messages["role"] == "assistant":
101
+ avatar = str(assets_dir / "robot_icon.png")
102
+ elif messages["role"] == "user":
103
+ avatar = str(assets_dir / "user.png")
104
+ else:
105
+ avatar = None # Default
106
+
107
+ with st.chat_message(messages["role"], avatar=avatar):
108
+ st.markdown(messages["content"])
109
+
110
+
111
+ prompt = st.chat_input("""نوشتن پیام""")
112
+
113
+ if prompt:
114
+ answer = prompt
115
+ answer = get_response(answer)
116
+ if answer == "L99":
117
+ state.result = "L99"
118
+
119
+ feedback = option_class.get_feedback("نتیجه", state.result)
120
+ st.switch_page("pages/result.py")
121
+ st.chat_message("user", avatar=str(assets_dir / "user.png")).markdown(prompt)
122
+ state.messages.append({"role": "user", "content": prompt})
123
+
124
+ if answer == "بله" or answer == "خیر":
125
+
126
+ next_level = option_class.get_next_level(answer, state.level)
127
+ feedback = option_class.get_feedback(answer, state.level)
128
+
129
+ if next_level != "L98" and next_level != "L99":
130
+ my_bar = st.progress(0, text=feedback)
131
+ for percent_complete in range(100):
132
+ time.sleep(0.01)
133
+ my_bar.progress(percent_complete + 1, text=feedback)
134
+ time.sleep(1)
135
+ my_bar.empty()
136
+ state.previous = state.level
137
+ state.level = next_level
138
+
139
+ resp = question_class.get_question_text(state.level)[0]
140
+ with st.chat_message("assistant"):
141
+ response = st.write_stream(response_generator(resp))
142
+ state.messages.append({"role": "assistant", "content": response})
143
+
144
+ elif next_level == "L98":
145
+ state.previous = state.level
146
+ state.level = next_level
147
+
148
+ state.result = feedback
149
+ st.switch_page("pages/result.py")
150
+ elif next_level == "L99":
151
+ state.result = feedback
152
+ st.switch_page("pages/result.py")
153
+
154
+ elif answer[0] == "L":
155
+
156
+ feedback = "تغییر بخش مورد بررسی, تا چند لحظه دیگر"
157
+ state.previous = state.level
158
+ next_level = answer
159
+ state.level = next_level
160
+ resp = question_class.get_question_text(state.level)[0]
161
+ with st.chat_message("assistant"):
162
+ response = st.write_stream(response_generator(resp))
163
+ state.messages.append({"role": "assistant", "content": response})
164
+
165
+ else:
166
+ with st.chat_message("assistant"):
167
+ answer = unknown()
168
+ response = st.write_stream(response_generator(answer))
169
+ state.messages.append({"role": "assistant", "content": response})
pages/2_result.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+ import time
3
+ from config.print_data import ConversationProcessor
4
+ import streamlit as st
5
+ from arabic_support import support_arabic_text
6
+ from pathlib import Path
7
+ from PIL import Image
8
+ from datetime import date
9
+ from navigation import make_sidebar
10
+
11
+
12
+
13
+
14
+ # st.set_page_config(
15
+ # page_title="Result",
16
+ # page_icon="✅",
17
+ # layout="wide",
18
+ # initial_sidebar_state="expanded",
19
+ # )
20
+ support_arabic_text(all=True)
21
+ time.sleep(.5)
22
+
23
+
24
+
25
+ state = st.session_state
26
+ current_file_path = Path(__file__).resolve()
27
+ project_root = current_file_path.parents[1]
28
+ assets_dir = project_root / "asset"
29
+ database_dir = project_root / "data"
30
+ styles_dir = project_root / "styles"
31
+ with open(styles_dir / "main.css", "r") as file:
32
+ css_code = file.read()
33
+
34
+ st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
35
+
36
+
37
+ side = st.sidebar
38
+
39
+ make_sidebar()
40
+
41
+
42
+ with side:
43
+ img = Image.open(assets_dir / "us.png")
44
+ st.image(img, width=250, caption="بررسی های صورت گرفته را میتوانید در این بخش دریافت نمایید")
45
+
46
+
47
+ def main():
48
+
49
+ st.title('بررسی نتایج و گزارش وضعیت')
50
+ if "result" not in state:
51
+ st.write("شما بررسی را آغاز نکرده‌اید. به صفحه اصلی بازگردید.")
52
+ st.stop()
53
+ st.markdown(state["result"])
54
+ processor = ConversationProcessor(state)
55
+
56
+ if st.button('ذخیره گزارش'):
57
+ output_file = f"{date.today()}_report.txt"
58
+ processor.save_conversation_to_text(output_file)
59
+
60
+ with open(output_file, 'r', encoding='utf-8') as f:
61
+ report_text = f.read()
62
+
63
+ st.text_area("گزارش", report_text, height=300)
64
+
65
+ st.download_button(
66
+ label="دانلود فایل متنی",
67
+ data=report_text,
68
+ file_name=output_file,
69
+ mime="text/plain"
70
+ )
71
+
72
+
73
+ if __name__ == "__main__":
74
+ main()
pages/3_data_entry.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from config.process_text import DataManager
2
+ import pandas as pd
3
+ import streamlit as st
4
+ from arabic_support import support_arabic_text
5
+ from pathlib import Path
6
+ from PIL import Image
7
+ from navigation import make_sidebar
8
+ import streamlit as st
9
+
10
+ # st.set_page_config(
11
+ # page_title="Data Entry",
12
+ # page_icon="📈",
13
+ # layout="wide",
14
+ # initial_sidebar_state="expanded",
15
+ # )
16
+
17
+ # پشتیبانی از متن عربی در تمامی اجزاء
18
+ support_arabic_text(all=True)
19
+
20
+ # مسیر فایل فعلی
21
+ current_file_path = Path(__file__).resolve()
22
+ # مسیر ریشه پروژه (یک سطح بالاتر از فایل فعلی)
23
+ project_root = current_file_path.parents[1]
24
+ # مسیرهای دایرکتوری‌ها
25
+ assets_dir = project_root / "asset"
26
+ database_dir = project_root / "data"
27
+ styles_dir = project_root / "styles"
28
+
29
+ # خواندن CSS از فایل
30
+ with open(styles_dir / "main.css", "r") as file:
31
+ css_code = file.read()
32
+
33
+ # اعمال CSS
34
+ st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
35
+
36
+ side = st.sidebar
37
+ state = st.session_state
38
+
39
+ make_sidebar()
40
+ if "message" not in state:
41
+ state["message"] = "No changes"
42
+
43
+
44
+ with side:
45
+ img = Image.open(assets_dir / "robot.png")
46
+ st.image(img, width=250, caption="Enter Data to DB")
47
+
48
+ messageboard = st.empty()
49
+
50
+ group_dict = {
51
+ "Movement Disorders": "L01",
52
+ "Chorea in Face, neck, upper limbs, Trunk, lower limbs, and generalized": "L02",
53
+ "Eye movement disorders and neurological symptoms": "L03",
54
+ "Neurometabolic Diseases": "L04",
55
+ "Hyperhomocysteinemia": "L06",
56
+ "Psychiatric manifestations": "L05",
57
+ "Spinal cord involvement": "L07",
58
+ "Intracellular Cobalamin Metabolism": "L08",
59
+ "Lysosomal acid lipase deficiency": "L09",
60
+ "Di-hydro Lipoamide Dehydrogenase Deficiency": "L10",
61
+ "hypophosphatemia": "L11",
62
+ "Non hepatic hyperammonemic encephalopathy complications following bariatric surgery": "L12",
63
+ "upper limb tremor": "L13",
64
+ "mitochondrial diseases": "L14",
65
+ }
66
+
67
+
68
+ def _clear_cache():
69
+ for key in st.session_state.keys():
70
+ del st.session_state[key]
71
+
72
+
73
+ def save_to_db():
74
+ return edited_df.to_csv(database_dir / "database.csv", index=False)
75
+
76
+
77
+ def _add_db_callback():
78
+ datamanager = DataManager()
79
+ if (
80
+ state.options != ""
81
+ and state.level != ""
82
+ and state.question_text != ""
83
+ and state.feedback != ""
84
+ ):
85
+ try:
86
+ group_id = datamanager.get_id(state.group_key)
87
+ datamanager.save_to_database(
88
+ state.level,
89
+ state.question_text,
90
+ group_id,
91
+ state.options,
92
+ state.feedback,
93
+ )
94
+ state["message"] = "saved!"
95
+ except IndexError as e:
96
+ st.error(e)
97
+
98
+
99
+ st.title("answer")
100
+ with st.form("answer_form", clear_on_submit=False):
101
+ col1, col2, col3 = st.columns([4, 1, 1])
102
+ with col1:
103
+ st.selectbox(
104
+ label="Group name", options=group_dict.keys(), key="group_key"
105
+ ) # Corrected the key parameter
106
+
107
+ with col2:
108
+ st.text_input(
109
+ label="Question id",
110
+ placeholder="Question id",
111
+ value=None,
112
+ key="level",
113
+ )
114
+ with col3:
115
+ st.text_input(
116
+ label="next",
117
+ placeholder="next",
118
+ value=None,
119
+ key="next",
120
+ )
121
+ st.text_area(
122
+ label="Question text",
123
+ value=None,
124
+ placeholder="Question text",
125
+ key="question_text",
126
+ )
127
+ st.text_input(
128
+ label="Option text", value=None, placeholder="Option text", key="option"
129
+ )
130
+ st.text_input(
131
+ label="action text", value=None, placeholder="action text", key="feedback"
132
+ )
133
+
134
+ submitted = st.form_submit_button(
135
+ "submitted",
136
+ on_click=_add_db_callback,
137
+ )
138
+
139
+ if submitted:
140
+ messageboard.info(state.message)
141
+
142
+ with st.expander("show data"):
143
+ df_db = pd.read_csv(database_dir / "database.csv")
144
+ edited_df = st.data_editor(
145
+ df_db,
146
+ num_rows="dynamic",
147
+ use_container_width=True,
148
+ hide_index=True,
149
+ on_change=save_to_db,
150
+ )
151
+ clear = st.button("Clear Cash", on_click=_clear_cache)
pages/4_About_us.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from pathlib import Path
3
+ from PIL import Image
4
+ import pandas as pd
5
+ import streamlit as st
6
+ from arabic_support import support_arabic_text
7
+ from config.handling import *
8
+ from navigation import make_sidebar
9
+ import streamlit as st
10
+
11
+
12
+ # st.set_page_config(
13
+ # page_title="About-us",
14
+ # page_icon="💊",
15
+ # layout="wide",
16
+ # initial_sidebar_state="expanded",
17
+ # )
18
+
19
+ # Support Arabic text alignment in all components
20
+ support_arabic_text(all=True)
21
+
22
+
23
+ current_file_path = Path(__file__).resolve()
24
+ project_root = current_file_path.parents[1]
25
+ assets_dir = project_root / "asset"
26
+ database_dir = project_root / "data"
27
+ styles_dir = project_root / "styles"
28
+
29
+
30
+
31
+ # Reading CSS from file
32
+ with open(styles_dir / "main.css", "r") as file:
33
+ css_code = file.read()
34
+
35
+ # Applying CSS
36
+ st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
37
+
38
+ side = st.sidebar
39
+ make_sidebar()
40
+ with side:
41
+ img = Image.open(assets_dir/"us.png")
42
+ st.image(img, width=250, caption="درباره ما")
43
+ with st.container():
44
+ st.title('درباره ما:')
45
+ banner = Image.open(assets_dir/"whoweare.jpg")
46
+ col1, col2 = st.columns([5, 3])
47
+ with col1:
48
+ st.image(banner)
49
+ with col2:
50
+ st.text_area("سازندگان:")
pages/5_print_data.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+ import streamlit as st
3
+ from config.print_data import ConversationProcessor
4
+ from arabic_support import support_arabic_text
5
+ from pathlib import Path
6
+ from PIL import Image
7
+ from datetime import date
8
+ from navigation import make_sidebar
9
+ import streamlit as st
10
+
11
+
12
+ # st.set_page_config(
13
+ # page_title="Data Handling",
14
+ # page_icon="📈",
15
+ # layout="wide",
16
+ # initial_sidebar_state="expanded",
17
+ # )
18
+
19
+ support_arabic_text(all=True)
20
+
21
+ current_file_path = Path(__file__).resolve()
22
+ project_root = current_file_path.parents[1]
23
+ assets_dir = project_root / "asset"
24
+ database_dir = project_root / "data"
25
+ styles_dir = project_root / "styles"
26
+
27
+ with open(styles_dir / "main.css", "r") as file:
28
+ css_code = file.read()
29
+
30
+ st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
31
+ side = st.sidebar
32
+
33
+ state = st.session_state
34
+
35
+ if "messages" not in state:
36
+ state["messages"] = []
37
+ start = """ سلام من دستیار شما هستم. برای بررسی و تصمیم گیری وضعیت بیماران مرحله به مرحله بررسی وضعیت بیمار را با کمک من انجام دهید. برای پیشنهاد می کنم
38
+ اختلالات حرکتی را بررسی کنید. آیا بیمار دارای چنین اختلالی است؟)"""
39
+
40
+ make_sidebar()
41
+ # Sidebar menu
42
+ with side:
43
+ # Display image
44
+ img = Image.open(assets_dir / "us.png")
45
+ st.image(img, width=250, caption="بررسی های صورت گرفته را میتوانید در این بخش دریافت نمایید")
46
+
47
+
48
+ def main():
49
+
50
+ st.title('بررسی نتایج و گزارش وضعیت')
51
+
52
+ processor = ConversationProcessor(state)
53
+
54
+ if st.button('ذخیره گزارش'):
55
+ output_file = f"{date.today()}_report.txt"
56
+ processor.save_conversation_to_text(output_file)
57
+
58
+ with open(output_file, 'r', encoding='utf-8') as file:
59
+ report_text = file.read()
60
+
61
+ st.text_area("گزارش", report_text, height=300)
62
+
63
+ st.download_button(
64
+ label="دانلود فایل متنی",
65
+ data=report_text,
66
+ file_name=output_file,
67
+ mime="text/plain"
68
+ )
69
+
70
+
71
+ if __name__ == "__main__":
72
+ main()
pages/6_upload_to_db.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ # from pathlib import Path
3
+ from PIL import Image
4
+ import pandas as pd
5
+ from arabic_support import support_arabic_text
6
+ import config.handling
7
+ from config.handling import *
8
+ from navigation import make_sidebar
9
+ import streamlit as st
10
+
11
+
12
+ #
13
+ # st.set_page_config(
14
+ # page_title="Upload Data",
15
+ # page_icon="📝",
16
+ # layout="wide",
17
+ # initial_sidebar_state="expanded",
18
+ # )
19
+ support_arabic_text(all=True)
20
+
21
+
22
+ current_file_path = Path(__file__).resolve()
23
+ project_root = current_file_path.parents[1]
24
+ assets_dir = project_root / "asset"
25
+ database_dir = project_root / "data"
26
+ styles_dir = project_root / "styles"
27
+
28
+ with open(styles_dir / "main.css", "r") as file:
29
+ css_code = file.read()
30
+
31
+ st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
32
+ side = st.sidebar
33
+
34
+ make_sidebar()
35
+ with side:
36
+
37
+ img = Image.open(assets_dir / "robot.png")
38
+
39
+ st.image(img, width=250, caption="بارگذاری داده ها")
40
+
41
+ st.title("بارگذاری در پایگاه داده")
42
+ uploaded_file = st.file_uploader(
43
+ "Choose a XLSX file", type=["xlsx"], accept_multiple_files=False
44
+ )
45
+ if uploaded_file is not None:
46
+ df = pd.read_excel(uploaded_file)
47
+ df = config.handling.data_cleaning(df)
48
+
49
+ df2 = data_cleaning(df)
50
+ quiz = quiz_maker(df2)
51
+ option = option_maker(df2)
52
+ df2.to_csv(database_dir / "data5.csv", index=False)
53
+ # st.write("filename:", uploaded_file.name)
54
+ df2 = pd.read_csv(database_dir / "data5.csv")
55
+ st.data_editor(df2)