digitalai commited on
Commit
f5eb4e1
1 Parent(s): 1fb7e5b
config/__pycache__/cfg.cpython-310.pyc ADDED
Binary file (925 Bytes). View file
 
config/__pycache__/conf.cpython-310.pyc ADDED
Binary file (4.64 kB). View file
 
config/__pycache__/handling.cpython-310.pyc ADDED
Binary file (1.65 kB). View file
 
config/__pycache__/long_responses.cpython-310.pyc ADDED
Binary file (956 Bytes). View file
 
config/__pycache__/option.cpython-310.pyc ADDED
Binary file (1.22 kB). View file
 
config/__pycache__/print_data.cpython-310.pyc ADDED
Binary file (965 Bytes). View file
 
config/__pycache__/process_text.cpython-310.pyc ADDED
Binary file (5.58 kB). View file
 
config/__pycache__/quiz.cpython-310.pyc ADDED
Binary file (1 kB). View file
 
config/__pycache__/valid_text.cpython-310.pyc ADDED
Binary file (2.39 kB). View file
 
config/conf.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+ import random
4
+ def message_probability(
5
+ user_message, recognised_words,
6
+ single_response=False, required_words=None
7
+ ):
8
+ if required_words is None:
9
+ required_words = []
10
+ message_certainty = 0
11
+ has_required_words = True
12
+
13
+ for word in user_message:
14
+ if word in recognised_words:
15
+ message_certainty += 1
16
+
17
+ percentage = float(message_certainty) / float(len(recognised_words))
18
+
19
+ for word in required_words:
20
+ if word not in user_message:
21
+ has_required_words = False
22
+ break
23
+
24
+ if has_required_words or single_response:
25
+ return int(percentage * 100)
26
+ else:
27
+ return 0
28
+
29
+ def unknown():
30
+ response = ["Could you please re-phrase that? ",
31
+ "...",
32
+ "Sounds about right.",
33
+ "What does that mean?"][
34
+ random.randrange(4)]
35
+ return response
36
+
37
+
38
+ def check_all_messages(message):
39
+ highest_prob_list = {}
40
+
41
+ def response(bot_response, list_of_words, single_response=False, required_words=[]):
42
+ nonlocal highest_prob_list
43
+ highest_prob_list[bot_response] = message_probability(message, list_of_words, single_response, required_words)
44
+
45
+ # Responses -------------------------------------------------------------------------------------------------------
46
+
47
+ response("بله", ["دارد", "نشانه", "علایم", "علائم", "بله"], required_words=["بله"])
48
+ response("خیر", ["ندارد", "نشانه‌ای", "علایمی", "خیر"], required_words=["خیر"])
49
+ response("L99", ["تمام", "خروج", "پایان", "l99"], required_words=["پایان"])
50
+
51
+ response("L01", ["اختلالات", "حرکتی", "Movement", "disorders","حرکت"],
52
+ required_words=["حرکت"])
53
+ response("L02", ["تعمیم یافته", "صورت", "گردن", "اندامهای", "رقصاک", "فوقانی", "تحتانی", "تنه"],
54
+ required_words=["رقصاک"])
55
+ response("L03", ["چشمی", "عصبی", "حرکت"
56
+ ], required_words=["عصبی"])
57
+ response("L04", ["بیماری‌", "عصبی", "متا", "بولیکی", "نورومتابولیکی"
58
+ ], required_words=["عصبی"])
59
+ response("L05", ["روان‌پزشکی", "روانپریشی", "روان", "پزشکی", "روانپزشکی"
60
+ ], required_words=["روانپزشکی"])
61
+ response("L06", ["هیپرهموسیستئینمی", "hyperhomocysteinemia","ژنتیکی"
62
+ ], required_words=["ژنتیکی"])
63
+ response("L07", ["درگیری", "طناب", "نخاعی", "spinal", "cord", "نخاعی"
64
+ ], required_words=["نخاعی"])
65
+ response("L08", ["کوبالامین", "داخل", "سلولی", "intracellular", "cobalamin","سلولی"
66
+ ], required_words=["سلولی"])
67
+
68
+ response("L09", ["لیپاز", "اسید", "لیزوزومال", "LAL-D", "کمبود"
69
+ ], required_words=["کمبود"])
70
+ response("L10", ["هیدرولیپوآمید", "دهیدروژناز", "کمبود"
71
+ ], required_words=["کمبود"])
72
+ response("L11", ["فسفاتمی","هایپوفسفاتمی", "هیپوفسفاتمی", "hypophosphatemia", "HP", "ژنتیکی"
73
+ ], required_words=["ژنتیکی"])
74
+ response("L12", ["آنسفالوپاتی", "هیپرآمونمیک", "غیر", "کبدی", "جراحی", "چاقی", "Nonhepatic", "hyperammonemic", "encephalopathy", "bariatric", "surgery", "NHE-BS"
75
+ ], required_words=["کبدی"])
76
+ response("L13", ["لرزش", "میتو", "کندری", "میتوکندری", "ژنتیکی"
77
+ ], required_words=["ژنتیکی"])
78
+ response("L14", ["اندام", "لرزش", "ترمور", "Tremor", "TRM"
79
+ ], required_words=["عصبی"])
80
+
81
+
82
+ best_match = max(highest_prob_list, key=highest_prob_list.get)
83
+ print(f'Best match = {best_match} | Score: {highest_prob_list[best_match]}')
84
+
85
+ return unknown() if highest_prob_list[best_match] < 1 else best_match
86
+
87
+
88
+ def replace_synonyms(sentence):
89
+ synonyms_dict = {
90
+ "بله": [
91
+ "بله", "بلی", "بلخ", "یله", "پله",
92
+ "آره", "آری", "آرخ", "yes", "ya", "bale", "ari",
93
+ "are", "fgi", "hvi", "Hvd", "Hvd", "fgd", "hsj",
94
+ "isj", "nhvn", "هست", "است", "دارد", "یس", "nhavd",
95
+ "هست", "احتمال دارد", "امکان دارد", "میتواند", "شاید",
96
+ "احتمال مثبت", "باشد", "می دهم", "یس", "yes", "yup",
97
+ "چک کن", "مشکوک", "دارد"
98
+ ],
99
+ "خیر": [
100
+ "نه", "منفی", "odv", "kodv", "خیر", "no", "ni", "نخیر",
101
+ "نیست", "نبود", "نمیشود", "نمی شود", "نمی\u200cشود", "نیست",
102
+ "ندیدم", "دخ", "nist", "nabod", "na", "nah", "noch", "nuch",
103
+ "nooch", "manfi", "udv"
104
+ ],
105
+ }
106
+ reverse_dict = {}
107
+ for key, synonyms in synonyms_dict.items():
108
+ for synonym in synonyms:
109
+ reverse_dict[synonym] = key
110
+
111
+ regex_pattern = r'\b(' + '|'.join(map(re.escape, reverse_dict.keys())) + r')\b'
112
+
113
+ def replace(match):
114
+ return reverse_dict[match.group(0)]
115
+
116
+ result = re.sub(regex_pattern, replace, sentence)
117
+ print(result)
118
+ return result
119
+
120
+ # Used to get the response
121
+ def get_response(user_input):
122
+ user_input = replace_synonyms(user_input)
123
+ split_message = re.split(r'\s+|[,;?!.-]\s*', user_input.lower())
124
+ response = check_all_messages(split_message)
125
+ return response
config/long_responses.py CHANGED
@@ -1,4 +1,9 @@
1
  import random
 
 
 
 
 
2
 
3
  R_EATING = "I don't like eating anything because I'm a bot obviously!"
4
  R_ADVICE = "If I were you, I would go to the internet and type exactly what you wrote there!"
 
1
  import random
2
+ from config.quiz import Question
3
+ from config.option import Option
4
+ import os
5
+ import pathlib
6
+
7
 
8
  R_EATING = "I don't like eating anything because I'm a bot obviously!"
9
  R_ADVICE = "If I were you, I would go to the internet and type exactly what you wrote there!"
config/print_data.py CHANGED
@@ -12,6 +12,4 @@ class ConversationProcessor:
12
  if role == 'user':
13
  file.write("User: " + content + "\n")
14
  elif role == 'assistant':
15
- file.write("Assistant: " + content + "\n")
16
-
17
- # print(f"مکالمات با موفقیت در فایل {output_file} ذخیره شدند.")
 
12
  if role == 'user':
13
  file.write("User: " + content + "\n")
14
  elif role == 'assistant':
15
+ file.write("Assistant: " + content + "\n")
 
 
config/valid_text.py CHANGED
@@ -7,13 +7,16 @@ def is_valid_input(user_input):
7
  "بله", "بلی", "بلخ", "یله", "پله",
8
  "آره", "آری", "آرخ", "yes", "ya", "bale", "ari",
9
  "are", "fgi", "hvi", "Hvd", "Hvd", "fgd", "hsj",
10
- "isj", "nhvn", "هست", "است", "دارد", "یس",
 
 
 
11
  ],
12
  "خیر": [
13
  "نه", "منفی", "odv", "kodv", "خیر", "no", "ni", "نخیر",
14
  "نیست", "نبود", "نمیشود", "نمی شود", "نمی\u200cشود", "نیست",
15
  "ندیدم", "دخ", "nist", "nabod", "na", "nah", "noch", "nuch",
16
- "nooch","manfi",
17
  ],
18
  }
19
  input_list = user_input.split(" ")
@@ -78,37 +81,4 @@ group_dict = {
78
  "عوارض آنسفالوپاتی غیر کبدی به دنبال جراحی باریاتریک": "L12",
79
  "لرزش اندام فوقانی": "L13",
80
  "بیماریهای میتوکندری": "L14",
81
- }
82
- # print(type(user_choice_level("فسفاتمی")))
83
- # for k in group_dict.keys():
84
- # lst = k.split()
85
- # print(lst)
86
-
87
- #
88
- # ['اختلالات', 'حرکتی']["اختلالات حرکتی","Movement" ,"disorders"]
89
- # ['رقصاک', 'تعمیم', 'یافته', 'صورت', 'گردن', 'اندامهای', 'فوقانی/تحتانی', 'تنه']
90
- # ['اختلالات', 'حرکات', 'چشم', 'علائم', 'عصبی'][ 'حرکات', 'چشم', 'عصبی']
91
- # ['بیماری', 'عصبی']["عصبی", "متابولیکی"]
92
- # ['هوموستئینمی', 'شدید']["هیپرهموسیستئینمی" , "hyperhomocysteinemia"]
93
- # ['تظاهرات', 'روانی',"روانشناسی"]["اختلالات","روانپزشکی","psychiatric","manifestations"]
94
- # ['درگیری', 'نخاع']["درگیری","طناب", "نخاعی", "spinal", "cord"]
95
- #
96
- # ['متابولیسم', 'کبدی', 'داخل', 'سلولی']["کوبالامین" "داخل" "سلولی" "intracellular" "cobalamin"]
97
- # ['کمبود', 'لیپاز', 'اسید', 'لیزوزومی']["لیپاز" "اسید" "لیزوزومال"]
98
- # ['کمبود', 'دی', 'هیدرو', 'لیپوامید', 'دی', 'هیدروژناز']["کمبود" ,"دی هیدرولیپو","آمید", "دهیدروژناز"]
99
- #
100
- #
101
- #
102
- #
103
- # ['فسفاتمی']["هایپوفسفاتمی"] ["hypophosphatemia","hp"]
104
- # ['عوارض', 'آنسفالوپاتی', 'کبدی','دنبال', 'جراحی', 'باریاتریک']
105
- # ["Nonhepatic", "hyperammonemic", "encephalopathy" ,"bariatric", "surgery", "آنسفالوپاتی"
106
- # , "هیپرآمونمیک", "کبدی", "جراحی" ,"چاقی" ,"NHEBS"]
107
- # ["لرزش","ترمور","Tremor"]
108
- #
109
- #
110
- #
111
- #
112
- # ['لرزش', 'اندام', 'فوقانی']
113
- # ['بیماریهای', 'میتوکندری']
114
- # ["درگیری","طناب", "نخاعی", "spinal", "cord"]
 
7
  "بله", "بلی", "بلخ", "یله", "پله",
8
  "آره", "آری", "آرخ", "yes", "ya", "bale", "ari",
9
  "are", "fgi", "hvi", "Hvd", "Hvd", "fgd", "hsj",
10
+ "isj", "nhvn", "هست", "است", "دارد", "یس", "nhavd",
11
+ "هست", "احتمال دارد", "امکان دارد", "میتواند", "شاید",
12
+ "احتمال مثبت", "باشد", "می دهم", "یس", "yes", "yup",
13
+ "چک کن", "مشکوک", "دارد"
14
  ],
15
  "خیر": [
16
  "نه", "منفی", "odv", "kodv", "خیر", "no", "ni", "نخیر",
17
  "نیست", "نبود", "نمیشود", "نمی شود", "نمی\u200cشود", "نیست",
18
  "ندیدم", "دخ", "nist", "nabod", "na", "nah", "noch", "nuch",
19
+ "nooch", "manfi", "udv"
20
  ],
21
  }
22
  input_list = user_input.split(" ")
 
81
  "عوارض آنسفالوپاتی غیر کبدی به دنبال جراحی باریاتریک": "L12",
82
  "لرزش اندام فوقانی": "L13",
83
  "بیماریهای میتوکندری": "L14",
84
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
data/.~lock.final.xlsx# ADDED
@@ -0,0 +1 @@
 
 
1
+ ,digi-ai,Digital-Ai,31.05.2024 12:56,file:///home/digi-ai/.config/libreoffice/4;
data/12.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/2.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/Data IEM with Tags.xlsx ADDED
Binary file (39.3 kB). View file
 
data/Data IEM without Tags.xlsx ADDED
Binary file (38.5 kB). View file
 
data/Data IEM3.xlsx ADDED
Binary file (30.6 kB). View file
 
data/data5.csv CHANGED
@@ -485,4 +485,4 @@ L13-01-01-01-01-01-01-01,چک کنید آیا آتاکسی، دیستونی، ب
485
  L13-01-01-01-01-01-01-01-01,چک کنید آیا دیستونی، پارکینسونیسم، لرزش وجود دارد و تستهای آزمایشگاهی مانند سطح دوپامین CSF؛ تجزیه و تحلیل ژنتیکی: GCH1 موید حضور Segawa disease (DRD) است؟,بله,احتمالا Segawa disease (DRD) است.,L99
486
  L13-01-01-01-01-01-01-01-01,چک کنید آیا دیستونی، پارکینسونیسم، لرزش وجود دارد و تستهای آزمایشگاهی مانند سطح دوپامین CSF؛ تجزیه و تحلیل ژنتیکی: GCH1 موید حضور Segawa disease (DRD) است؟,خیر,منتظر مرحله بعدی بمانید,L13-01-01-01-01-01-01-01-01-01
487
  L13-01-01-01-01-01-01-01-01-01,چک کنید آیا آتاکسی، دیستونی، لرزش، اسپاستیسیتی وجود دارد و تستهای آزمایشگاهی مانند لاکتات سرم، فعالیت های بیوشیمیایی مجموعه های زنجیره تنفسی در پوست یا ماهیچه، سطح CoQ10 عضلانی. تجزیه و تحلیل ژنتیکی: چندین ژن موید حضور Coenzyme Q10 deficiency هستند؟,بله,احتمالا Coenzyme Q10 deficiency است.,L99
488
- L13-01-01-01-01-01-01-01-01-01,چک کنید آیا آتاکسی، دیستونی، لرزش، اسپاستیسیتی وجود دارد و تستهای آزمایشگاهی مانند لاکتات سرم، فعالیت های بیوشیمیایی مجموعه های زنجیره تنفسی در پوست یا ماهیچه، سطح CoQ10 عضلانی. تجزیه و تحلیل ژنتیکی: چندین ژن موید حضور Coenzyme Q10 deficiency هستند؟,خیر,از روش‌های دیگری برای تشخیص استفاده نمایید,L99
 
485
  L13-01-01-01-01-01-01-01-01,چک کنید آیا دیستونی، پارکینسونیسم، لرزش وجود دارد و تستهای آزمایشگاهی مانند سطح دوپامین CSF؛ تجزیه و تحلیل ژنتیکی: GCH1 موید حضور Segawa disease (DRD) است؟,بله,احتمالا Segawa disease (DRD) است.,L99
486
  L13-01-01-01-01-01-01-01-01,چک کنید آیا دیستونی، پارکینسونیسم، لرزش وجود دارد و تستهای آزمایشگاهی مانند سطح دوپامین CSF؛ تجزیه و تحلیل ژنتیکی: GCH1 موید حضور Segawa disease (DRD) است؟,خیر,منتظر مرحله بعدی بمانید,L13-01-01-01-01-01-01-01-01-01
487
  L13-01-01-01-01-01-01-01-01-01,چک کنید آیا آتاکسی، دیستونی، لرزش، اسپاستیسیتی وجود دارد و تستهای آزمایشگاهی مانند لاکتات سرم، فعالیت های بیوشیمیایی مجموعه های زنجیره تنفسی در پوست یا ماهیچه، سطح CoQ10 عضلانی. تجزیه و تحلیل ژنتیکی: چندین ژن موید حضور Coenzyme Q10 deficiency هستند؟,بله,احتمالا Coenzyme Q10 deficiency است.,L99
488
+ L13-01-01-01-01-01-01-01-01-01,چک کنید آیا آتاکسی، دیستونی، لرزش، اسپاستیسیتی وجود دارد و تستهای آزمایشگاهی مانند لاکتات سرم، فعالیت های بیوشیمیایی مجموعه های زنجیره تنفسی در پوست یا ماهیچه، سطح CoQ10 عضلانی. تجزیه و تحلیل ژنتیکی: چندین ژن موید حضور Coenzyme Q10 deficiency هستند؟,خیر,از روش‌های دیگری برای تشخیص استفاده نمایید,L99
data/option_data.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
- "L99": {
3
  "شروع": {
4
  "feedback": "شروع بررسی وضعیت",
5
  "next": "L01"
@@ -9,10 +9,10 @@
9
  "next": "L99"
10
  }
11
  },
12
- "L98": {
13
  "نتیجه": {
14
  "feedback": "خاتمه بررسی ",
15
- "next": "L01"
16
  }
17
  },
18
  "L01": {
@@ -27,12 +27,12 @@
27
  },
28
  "L01-01": {
29
  "بله": {
30
- "feedback": "منتظر مرحله بعدی بمانید",
31
- "next": "L01-01-01"
32
  },
33
  "خیر": {
34
- "feedback": "علائم بالینی بعدی را چک کنید",
35
- "next": "L02"
36
  }
37
  },
38
  "L01-01-01": {
 
1
  {
2
+ "L98": {
3
  "شروع": {
4
  "feedback": "شروع بررسی وضعیت",
5
  "next": "L01"
 
9
  "next": "L99"
10
  }
11
  },
12
+ "L99": {
13
  "نتیجه": {
14
  "feedback": "خاتمه بررسی ",
15
+ "next": ""
16
  }
17
  },
18
  "L01": {
 
27
  },
28
  "L01-01": {
29
  "بله": {
30
+ "feedback": "بیماریت کشفیده شد",
31
+ "next": "L99"
32
  },
33
  "خیر": {
34
+ "feedback": "بیماریت کشفیده شد",
35
+ "next": "L99"
36
  }
37
  },
38
  "L01-01-01": {
main.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 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()
22
+ # مسیر ریشه پروژه (دو سطح بالاتر از فایل فعلی)
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"
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
+
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/print_data.py CHANGED
@@ -8,40 +8,28 @@ from datetime import date
8
 
9
 
10
  current_file_path = Path(__file__).resolve()
11
- # مسیر ریشه پروژه (یک سطح بالاتر از فایل فعلی)
12
  project_root = current_file_path.parents[1]
13
- # مسیرهای دایرکتوری‌ها
14
  assets_dir = project_root / "asset"
15
  database_dir = project_root / "data"
16
  styles_dir = project_root / "styles"
17
 
18
- # Streamlit page configuration
19
  st.set_page_config(
20
  page_title="Data Handling",
21
  page_icon="📈",
22
  layout="wide",
23
  initial_sidebar_state="expanded",
24
  )
25
- # پشتیبانی از متن عربی در تمامی اجزاء
26
  support_arabic_text(all=True)
27
- # خواندن CSS از فایل
28
  with open(styles_dir / "main.css", "r") as file:
29
  css_code = file.read()
30
 
31
- # اعمال CSS
32
  st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
33
  side = st.sidebar
34
 
35
- # Initialize session state
36
  state = st.session_state
37
  if "messages" not in state:
38
  state["messages"] = []
39
- if "start" not in state:
40
- state["start"] = """سلام من دستیار شما هستم. برای بررسی و تصمیم گیری وضعیت بیماران
41
- مرحله به مرحله بررسی وضعیت بیمار را با کمک من انجام دهید.برای شروع پیشنهاد
42
- می‌کنم اختلالات حرکتی را بررسی کنید. آیا بیمار دارای چنین اختلالی است؟"""
43
 
44
- # پشتیبانی از متن عربی در تمامی اجزاء
45
  support_arabic_text(all=True)
46
 
47
  # Sidebar menu
 
8
 
9
 
10
  current_file_path = Path(__file__).resolve()
 
11
  project_root = current_file_path.parents[1]
 
12
  assets_dir = project_root / "asset"
13
  database_dir = project_root / "data"
14
  styles_dir = project_root / "styles"
15
 
 
16
  st.set_page_config(
17
  page_title="Data Handling",
18
  page_icon="📈",
19
  layout="wide",
20
  initial_sidebar_state="expanded",
21
  )
 
22
  support_arabic_text(all=True)
 
23
  with open(styles_dir / "main.css", "r") as file:
24
  css_code = file.read()
25
 
 
26
  st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
27
  side = st.sidebar
28
 
 
29
  state = st.session_state
30
  if "messages" not in state:
31
  state["messages"] = []
 
 
 
 
32
 
 
33
  support_arabic_text(all=True)
34
 
35
  # Sidebar menu
pages/result.py CHANGED
@@ -7,46 +7,33 @@ from PIL import Image
7
  from datetime import date
8
 
9
 
 
 
10
  current_file_path = Path(__file__).resolve()
11
- # مسیر ریشه پروژه (یک سطح بالاتر از فایل فعلی)
12
  project_root = current_file_path.parents[1]
13
- # مسیرهای دایرکتوری‌ها
14
  assets_dir = project_root / "asset"
15
  database_dir = project_root / "data"
16
  styles_dir = project_root / "styles"
17
 
18
- # Streamlit page configuration
19
  st.set_page_config(
20
- page_title="Data Handling",
21
- page_icon="📈",
22
  layout="wide",
23
  initial_sidebar_state="expanded",
24
  )
25
- # پشتیبانی از متن عربی در تمامی اجزاء
26
  support_arabic_text(all=True)
27
- # خواندن CSS از فایل
28
  with open(styles_dir / "main.css", "r") as file:
29
  css_code = file.read()
30
 
31
- # اعمال CSS
32
  st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
 
 
33
  side = st.sidebar
34
 
35
- # Initialize session state
36
- state = st.session_state
37
- if "messages" not in state:
38
- state["messages"] = []
39
- if "start" not in state:
40
- state["start"] = """سلام من دستیار شما هستم. برای بررسی و تصمیم گیری وضعیت بیماران
41
- مرحله به مرحله بررسی وضعیت بیمار را با کمک من انجام دهید.برای شروع پیشنهاد
42
- می‌کنم اختلالات حرکتی را بررسی کنید. آیا بیمار دارای چنین اختلالی است؟"""
43
-
44
- # پشتیبانی از متن عربی در تمامی اجزاء
45
  support_arabic_text(all=True)
46
 
47
- # Sidebar menu
48
  with side:
49
- # Display image
50
  img = Image.open(assets_dir / "us.png")
51
  st.image(img, width=250, caption="بررسی های صورت گرفته را میتوانید در این بخش دریافت نمایید")
52
 
@@ -54,7 +41,10 @@ with side:
54
  def main():
55
 
56
  st.title('بررسی نتایج و گزارش وضعیت')
57
-
 
 
 
58
  processor = ConversationProcessor(state)
59
 
60
  if st.button('ذخیره گزارش'):
 
7
  from datetime import date
8
 
9
 
10
+
11
+ state = st.session_state
12
  current_file_path = Path(__file__).resolve()
 
13
  project_root = current_file_path.parents[1]
 
14
  assets_dir = project_root / "asset"
15
  database_dir = project_root / "data"
16
  styles_dir = project_root / "styles"
17
 
 
18
  st.set_page_config(
19
+ page_title="Result",
20
+ page_icon="",
21
  layout="wide",
22
  initial_sidebar_state="expanded",
23
  )
 
24
  support_arabic_text(all=True)
 
25
  with open(styles_dir / "main.css", "r") as file:
26
  css_code = file.read()
27
 
 
28
  st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
29
+
30
+
31
  side = st.sidebar
32
 
33
+
 
 
 
 
 
 
 
 
 
34
  support_arabic_text(all=True)
35
 
 
36
  with side:
 
37
  img = Image.open(assets_dir / "us.png")
38
  st.image(img, width=250, caption="بررسی های صورت گرفته را میتوانید در این بخش دریافت نمایید")
39
 
 
41
  def main():
42
 
43
  st.title('بررسی نتایج و گزارش وضعیت')
44
+ if "result" not in state:
45
+ st.write("شما بررسی را آغاز نکرده‌اید. به صفحه اصلی بازگردید.")
46
+ st.stop()
47
+ st.markdown(state["result"])
48
  processor = ConversationProcessor(state)
49
 
50
  if st.button('ذخیره گزارش'):
pages/upload_to_db.py CHANGED
@@ -21,13 +21,10 @@ st.set_page_config(
21
  layout="wide",
22
  initial_sidebar_state="expanded",
23
  )
24
- # Support Arabic text alignment in all components
25
  support_arabic_text(all=True)
26
- # Reading CSS from file
27
  with open(styles_dir / "main.css", "r") as file:
28
  css_code = file.read()
29
 
30
- # Applying CSS
31
  st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
32
  side = st.sidebar
33
 
 
21
  layout="wide",
22
  initial_sidebar_state="expanded",
23
  )
 
24
  support_arabic_text(all=True)
 
25
  with open(styles_dir / "main.css", "r") as file:
26
  css_code = file.read()
27
 
 
28
  st.markdown(f"<style>{css_code}</style>", unsafe_allow_html=True)
29
  side = st.sidebar
30
 
styles/main.css CHANGED
@@ -47,7 +47,7 @@ ul {
47
  /* Style hr element */
48
  hr {
49
  margin-top: 16px;
50
- margin-bottom: 5%;
51
  }
52
 
53
  /* Headings */
@@ -57,15 +57,22 @@ h1 {
57
  text-align: center;
58
  direction: rtl;
59
  padding-bottom: 30px;
 
60
  }
 
 
 
 
 
61
 
 
62
  /* Body */
63
  body {
64
  /*background-color: #f0f2f6;*/
65
  font-family: 'IRANSans', sans-serif;
66
  text-align: right;
67
  direction: rtl;
68
- padding-top: 50px;
69
  background-Color:#1c223f;
70
 
71
  secondaryBackgroundColor:#1c223f;
@@ -142,20 +149,6 @@ body {
142
  padding: .5rem; /* فضای داخلی */
143
  margin: .5%; /* فضای بیرونی */
144
  }
145
-
146
- .st-emotion-cache-1acdeck {
147
- all: unset;
148
- text-align: center;
149
- direction: rtl;
150
- font-size: 30px !important;
151
- font-family: 'IRANSans', sans-serif;
152
- border-radius: 5px;
153
- border-color: #1184e6;
154
- margin-top: 1%;
155
- }
156
- /*background-color:
157
-
158
- }
159
  /* Hide Streamlit elements */
160
  #MainMenu, footer, header {
161
  visibility: hidden;
@@ -163,7 +156,16 @@ body {
163
  st-emotion-cache-12rcsx5.e1nzilvr4{
164
  padding-top: 2em !important;
165
  }
166
- /* General link styling for specific classes */
 
 
 
 
 
 
 
 
 
167
  [class^="st-emotion-cache-"]:active{
168
  text-decoration: none;
169
  font-weight: 800;
@@ -171,10 +173,88 @@ st-emotion-cache-12rcsx5.e1nzilvr4{
171
 
172
 
173
  }
174
- [class^="st-emotion-cache-"]:visited,
175
- [class^="st-emotion-cache-"]:hover {
176
- text-decoration: none;
177
- font-weight: 500;
178
 
 
179
  }
180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  /* Style hr element */
48
  hr {
49
  margin-top: 16px;
50
+ margin-bottom: 16px;
51
  }
52
 
53
  /* Headings */
 
57
  text-align: center;
58
  direction: rtl;
59
  padding-bottom: 30px;
60
+ font-size: 3rem;
61
  }
62
+ p {
63
+ font-family: 'IRANSans', sans-serif;
64
+ text-align: right;
65
+ direction: rtl;
66
+ font-size: 1.1rem;
67
 
68
+ }
69
  /* Body */
70
  body {
71
  /*background-color: #f0f2f6;*/
72
  font-family: 'IRANSans', sans-serif;
73
  text-align: right;
74
  direction: rtl;
75
+ padding-top: 2rem;
76
  background-Color:#1c223f;
77
 
78
  secondaryBackgroundColor:#1c223f;
 
149
  padding: .5rem; /* فضای داخلی */
150
  margin: .5%; /* فضای بیرونی */
151
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  /* Hide Streamlit elements */
153
  #MainMenu, footer, header {
154
  visibility: hidden;
 
156
  st-emotion-cache-12rcsx5.e1nzilvr4{
157
  padding-top: 2em !important;
158
  }
159
+ .st-emotion-cache-1jzia57.e1nzilvr2 {
160
+ padding-bottom: 20px;
161
+ margin-top: -50px;
162
+ font-size: 3rem;
163
+
164
+
165
+ }
166
+
167
+
168
+ /* General link styling for specific classes */
169
  [class^="st-emotion-cache-"]:active{
170
  text-decoration: none;
171
  font-weight: 800;
 
173
 
174
 
175
  }
176
+ [class^="st-emotion-cache-"]:visited,
177
+ [class^="st-emotion-cache-"]:hover {
178
+ text-decoration: none;
179
+ font-weight: 500;
180
 
181
+ }
182
  }
183
 
184
+
185
+
186
+
187
+
188
+
189
+ /*.stSidebar {*/
190
+ /* padding: 2px !important;*/
191
+ /* background-color: #070E1C;*/
192
+ /*}*/
193
+
194
+ /*!* Icon *!*/
195
+ /*.stSidebar .icon {*/
196
+ /* color: orange;*/
197
+ /* font-size: 16px;*/
198
+ /*}*/
199
+
200
+ /*!* Nav link *!*/
201
+ /*.stSidebar .nav-link {*/
202
+ /* font-size: 16px;*/
203
+ /* text-align: left;*/
204
+ /* margin: 0px;*/
205
+ /*}*/
206
+
207
+ /*!* Hover color *!*/
208
+ /*.stSidebar .nav-link:hover {*/
209
+ /* --hover-color: #F30080;*/
210
+ /*}*/
211
+
212
+ /*!* Selected nav link *!*/
213
+ /*.stSidebar .nav-link-selected {*/
214
+ /* background-color: #070E1C;*/
215
+ /*}*/
216
+ /*a {*/
217
+ /* text-decoration: none;*/
218
+ /* color: white !important;*/
219
+ /* font-weight: 500;*/
220
+ /*}*/
221
+
222
+ /*a:hover {*/
223
+ /* color: #d33682 !important;*/
224
+ /* text-decoration: none;*/
225
+ /*}*/
226
+
227
+ /*ul {list-style-type: none;}*/
228
+
229
+ /*hr {*/
230
+ /* margin-top: 0;*/
231
+ /* margin-bottom: 5%;*/
232
+ /*}*/
233
+ /*!* style.css *!*/
234
+ /*h1 {*/
235
+ /* background-color: #d60222;*/
236
+ /* font-family: 'IRANSans', sans-serif;*/
237
+ /* text-align: center;*/
238
+ /* direction: rtl;*/
239
+ /* padding-bottom: 30px;*/
240
+ /*}*/
241
+
242
+ /*body {*/
243
+ /* background-color: #f0f2f6;*/
244
+ /* font-family: 'IRANSans', sans-serif;*/
245
+ /* text-align: right;*/
246
+ /* direction: rtl;*/
247
+ /* padding-top: 50px;*/
248
+ /*}*/
249
+
250
+ /*.stButton>button {*/
251
+ /* background-color: #4CAF50;*/
252
+ /* color: white;*/
253
+ /* border-radius: 5px;*/
254
+ /* padding: 1rem;*/
255
+ /* margin: .5em !important;*/
256
+ /*}*/
257
+
258
+ /*#MainMenu {visibility: hidden;}*/
259
+ /*footer {visibility: hidden;}*/
260
+ /*header {visibility: hidden;}*/