Spaces:
Sleeping
Sleeping
Vela
commited on
Commit
·
0f6ea9a
0
Parent(s):
updated the folder structure
Browse files- .gitignore +3 -0
- logs/api/yuvabe_care_companion_ai_api.log +173 -0
- logs/api/yuvabe_care_companion_ai_app.log +77 -0
- requirements.txt +12 -0
- src/backend/__pycache__/main.cpython-313.pyc +0 -0
- src/backend/data/__pycache__/chroma_db.cpython-313.pyc +0 -0
- src/backend/data/__pycache__/dataset.cpython-313.pyc +0 -0
- src/backend/data/chroma_db.py +67 -0
- src/backend/data/dataset.py +37 -0
- src/backend/main.py +6 -0
- src/backend/models/__pycache__/llm_model.cpython-313.pyc +0 -0
- src/backend/models/__pycache__/schemas.cpython-313.pyc +0 -0
- src/backend/models/llm_model.py +63 -0
- src/backend/models/schemas.py +6 -0
- src/backend/routes/__init__.py +1 -0
- src/backend/routes/__pycache__/__init__.cpython-313.pyc +0 -0
- src/backend/routes/__pycache__/chat_api.cpython-313.pyc +0 -0
- src/backend/routes/chat_api.py +18 -0
- src/backend/utils/__init__.py +1 -0
- src/backend/utils/__pycache__/__init__.cpython-313.pyc +0 -0
- src/backend/utils/__pycache__/logger.cpython-313.pyc +0 -0
- src/backend/utils/logger.py +35 -0
- src/frontend/app/__pycache__/__init__.cpython-313.pyc +0 -0
- src/frontend/app/__pycache__/common_fuctions.cpython-313.pyc +0 -0
- src/frontend/app/__pycache__/homepage.cpython-313.pyc +0 -0
- src/frontend/app/common_fuctions.py +26 -0
- src/frontend/app/homepage.py +133 -0
- src/frontend/home.py +4 -0
- src/frontend/images/page_icon.jpg +0 -0
- src/frontend/pages/database_response_page.py +3 -0
- src/frontend/utils/__pycache__/logger.cpython-313.pyc +0 -0
- src/frontend/utils/logger.py +35 -0
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
.venv
|
2 |
+
.env
|
3 |
+
vector-db
|
logs/api/yuvabe_care_companion_ai_api.log
ADDED
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
2025-03-06 20:02 - INFO - Hello World
|
2 |
+
2025-03-06 20:02 - INFO - Hello World
|
3 |
+
2025-03-06 20:22 - INFO - src/data/dataset.csv not found. Reading from Parquet file.
|
4 |
+
2025-03-06 20:22 - ERROR - Error while loading dataset: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
|
5 |
+
A suitable version of pyarrow or fastparquet is required for parquet support.
|
6 |
+
Trying to import the above resulted in these errors:
|
7 |
+
- Missing optional dependency 'pyarrow'. pyarrow is required for parquet support. Use pip or conda to install pyarrow.
|
8 |
+
- Missing optional dependency 'fastparquet'. fastparquet is required for parquet support. Use pip or conda to install fastparquet.
|
9 |
+
Traceback (most recent call last):
|
10 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\src\backend\data\dataset.py", line 16, in get_data_set
|
11 |
+
df = pd.read_parquet(PARAQUET_DATASET_PATH)
|
12 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\.venv\Lib\site-packages\pandas\io\parquet.py", line 651, in read_parquet
|
13 |
+
impl = get_engine(engine)
|
14 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\.venv\Lib\site-packages\pandas\io\parquet.py", line 67, in get_engine
|
15 |
+
raise ImportError(
|
16 |
+
...<7 lines>...
|
17 |
+
)
|
18 |
+
ImportError: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
|
19 |
+
A suitable version of pyarrow or fastparquet is required for parquet support.
|
20 |
+
Trying to import the above resulted in these errors:
|
21 |
+
- Missing optional dependency 'pyarrow'. pyarrow is required for parquet support. Use pip or conda to install pyarrow.
|
22 |
+
- Missing optional dependency 'fastparquet'. fastparquet is required for parquet support. Use pip or conda to install fastparquet.
|
23 |
+
2025-03-06 20:22 - ERROR - 'NoneType' object has no attribute 'head'
|
24 |
+
2025-03-06 20:24 - INFO - src/backend/data/dataset.csv not found. Reading from Parquet file.
|
25 |
+
2025-03-06 20:24 - ERROR - Error while loading dataset: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
|
26 |
+
A suitable version of pyarrow or fastparquet is required for parquet support.
|
27 |
+
Trying to import the above resulted in these errors:
|
28 |
+
- Missing optional dependency 'pyarrow'. pyarrow is required for parquet support. Use pip or conda to install pyarrow.
|
29 |
+
- Missing optional dependency 'fastparquet'. fastparquet is required for parquet support. Use pip or conda to install fastparquet.
|
30 |
+
Traceback (most recent call last):
|
31 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\src\backend\data\dataset.py", line 16, in get_data_set
|
32 |
+
df = pd.read_parquet(PARAQUET_DATASET_PATH)
|
33 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\.venv\Lib\site-packages\pandas\io\parquet.py", line 651, in read_parquet
|
34 |
+
impl = get_engine(engine)
|
35 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\.venv\Lib\site-packages\pandas\io\parquet.py", line 67, in get_engine
|
36 |
+
raise ImportError(
|
37 |
+
...<7 lines>...
|
38 |
+
)
|
39 |
+
ImportError: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
|
40 |
+
A suitable version of pyarrow or fastparquet is required for parquet support.
|
41 |
+
Trying to import the above resulted in these errors:
|
42 |
+
- Missing optional dependency 'pyarrow'. pyarrow is required for parquet support. Use pip or conda to install pyarrow.
|
43 |
+
- Missing optional dependency 'fastparquet'. fastparquet is required for parquet support. Use pip or conda to install fastparquet.
|
44 |
+
2025-03-06 20:24 - ERROR - 'NoneType' object has no attribute 'head'
|
45 |
+
2025-03-06 20:24 - INFO - src/backend/data/dataset.csv not found. Reading from Parquet file.
|
46 |
+
2025-03-06 20:24 - ERROR - Error while loading dataset: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
|
47 |
+
A suitable version of pyarrow or fastparquet is required for parquet support.
|
48 |
+
Trying to import the above resulted in these errors:
|
49 |
+
- Missing optional dependency 'pyarrow'. pyarrow is required for parquet support. Use pip or conda to install pyarrow.
|
50 |
+
- Missing optional dependency 'fastparquet'. fastparquet is required for parquet support. Use pip or conda to install fastparquet.
|
51 |
+
Traceback (most recent call last):
|
52 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\src\backend\data\dataset.py", line 16, in get_data_set
|
53 |
+
df = pd.read_parquet(PARAQUET_DATASET_PATH)
|
54 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\.venv\Lib\site-packages\pandas\io\parquet.py", line 651, in read_parquet
|
55 |
+
impl = get_engine(engine)
|
56 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\.venv\Lib\site-packages\pandas\io\parquet.py", line 67, in get_engine
|
57 |
+
raise ImportError(
|
58 |
+
...<7 lines>...
|
59 |
+
)
|
60 |
+
ImportError: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
|
61 |
+
A suitable version of pyarrow or fastparquet is required for parquet support.
|
62 |
+
Trying to import the above resulted in these errors:
|
63 |
+
- Missing optional dependency 'pyarrow'. pyarrow is required for parquet support. Use pip or conda to install pyarrow.
|
64 |
+
- Missing optional dependency 'fastparquet'. fastparquet is required for parquet support. Use pip or conda to install fastparquet.
|
65 |
+
2025-03-06 20:24 - ERROR - 'NoneType' object has no attribute 'head'
|
66 |
+
2025-03-06 20:25 - INFO - src/backend/data/dataset.csv not found. Reading from Parquet file.
|
67 |
+
2025-03-06 20:25 - ERROR - Error while loading dataset: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
|
68 |
+
A suitable version of pyarrow or fastparquet is required for parquet support.
|
69 |
+
Trying to import the above resulted in these errors:
|
70 |
+
- Missing optional dependency 'pyarrow'. pyarrow is required for parquet support. Use pip or conda to install pyarrow.
|
71 |
+
- Missing optional dependency 'fastparquet'. fastparquet is required for parquet support. Use pip or conda to install fastparquet.
|
72 |
+
Traceback (most recent call last):
|
73 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\src\backend\data\dataset.py", line 16, in get_data_set
|
74 |
+
df = pd.read_parquet(PARAQUET_DATASET_PATH)
|
75 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\.venv\Lib\site-packages\pandas\io\parquet.py", line 651, in read_parquet
|
76 |
+
impl = get_engine(engine)
|
77 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\.venv\Lib\site-packages\pandas\io\parquet.py", line 67, in get_engine
|
78 |
+
raise ImportError(
|
79 |
+
...<7 lines>...
|
80 |
+
)
|
81 |
+
ImportError: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
|
82 |
+
A suitable version of pyarrow or fastparquet is required for parquet support.
|
83 |
+
Trying to import the above resulted in these errors:
|
84 |
+
- Missing optional dependency 'pyarrow'. pyarrow is required for parquet support. Use pip or conda to install pyarrow.
|
85 |
+
- Missing optional dependency 'fastparquet'. fastparquet is required for parquet support. Use pip or conda to install fastparquet.
|
86 |
+
2025-03-06 20:25 - ERROR - 'NoneType' object has no attribute 'head'
|
87 |
+
2025-03-06 20:27 - INFO - src/backend/data/dataset.csv not found. Reading from Parquet file.
|
88 |
+
2025-03-06 20:27 - ERROR - Error while loading dataset: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
|
89 |
+
A suitable version of pyarrow or fastparquet is required for parquet support.
|
90 |
+
Trying to import the above resulted in these errors:
|
91 |
+
- Missing optional dependency 'pyarrow'. pyarrow is required for parquet support. Use pip or conda to install pyarrow.
|
92 |
+
- Missing optional dependency 'fastparquet'. fastparquet is required for parquet support. Use pip or conda to install fastparquet.
|
93 |
+
Traceback (most recent call last):
|
94 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\src\backend\data\dataset.py", line 16, in get_data_set
|
95 |
+
df = pd.read_parquet(PARAQUET_DATASET_PATH)
|
96 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\.venv\Lib\site-packages\pandas\io\parquet.py", line 651, in read_parquet
|
97 |
+
impl = get_engine(engine)
|
98 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\.venv\Lib\site-packages\pandas\io\parquet.py", line 67, in get_engine
|
99 |
+
raise ImportError(
|
100 |
+
...<7 lines>...
|
101 |
+
)
|
102 |
+
ImportError: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
|
103 |
+
A suitable version of pyarrow or fastparquet is required for parquet support.
|
104 |
+
Trying to import the above resulted in these errors:
|
105 |
+
- Missing optional dependency 'pyarrow'. pyarrow is required for parquet support. Use pip or conda to install pyarrow.
|
106 |
+
- Missing optional dependency 'fastparquet'. fastparquet is required for parquet support. Use pip or conda to install fastparquet.
|
107 |
+
2025-03-06 20:27 - INFO - Hello World
|
108 |
+
2025-03-06 20:27 - ERROR - 'NoneType' object has no attribute 'to_dict'
|
109 |
+
2025-03-06 20:28 - INFO - src/backend/data/dataset.csv not found. Reading from Parquet file.
|
110 |
+
2025-03-06 20:28 - ERROR - Error while loading dataset: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
|
111 |
+
A suitable version of pyarrow or fastparquet is required for parquet support.
|
112 |
+
Trying to import the above resulted in these errors:
|
113 |
+
- Missing optional dependency 'pyarrow'. pyarrow is required for parquet support. Use pip or conda to install pyarrow.
|
114 |
+
- Missing optional dependency 'fastparquet'. fastparquet is required for parquet support. Use pip or conda to install fastparquet.
|
115 |
+
Traceback (most recent call last):
|
116 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\src\backend\data\dataset.py", line 16, in get_data_set
|
117 |
+
df = pd.read_parquet(PARAQUET_DATASET_PATH)
|
118 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\.venv\Lib\site-packages\pandas\io\parquet.py", line 651, in read_parquet
|
119 |
+
impl = get_engine(engine)
|
120 |
+
File "C:\Users\Vijay\OneDrive\Desktop\Yuvabe_Care_Companion_AI\.venv\Lib\site-packages\pandas\io\parquet.py", line 67, in get_engine
|
121 |
+
raise ImportError(
|
122 |
+
...<7 lines>...
|
123 |
+
)
|
124 |
+
ImportError: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
|
125 |
+
A suitable version of pyarrow or fastparquet is required for parquet support.
|
126 |
+
Trying to import the above resulted in these errors:
|
127 |
+
- Missing optional dependency 'pyarrow'. pyarrow is required for parquet support. Use pip or conda to install pyarrow.
|
128 |
+
- Missing optional dependency 'fastparquet'. fastparquet is required for parquet support. Use pip or conda to install fastparquet.
|
129 |
+
2025-03-06 20:28 - INFO - Hello World
|
130 |
+
2025-03-06 20:28 - ERROR - 'NoneType' object has no attribute 'to_dict'
|
131 |
+
2025-03-06 20:57 - INFO - src/backend/data/dataset.csv not found. Reading from Parquet file.
|
132 |
+
2025-03-06 20:57 - INFO - CSV file created and cleaned at: src/backend/data/dataset.csv
|
133 |
+
2025-03-06 21:00 - INFO - Loading existing dataset from: src/backend/data/dataset.csv
|
134 |
+
2025-03-06 21:00 - INFO - Dataset loaded successfully.
|
135 |
+
2025-03-06 21:02 - INFO - Loading existing dataset from: src/backend/data/dataset.csv
|
136 |
+
2025-03-06 21:02 - INFO - Dataset loaded successfully.
|
137 |
+
2025-03-06 21:04 - INFO - Loading existing dataset from: src/backend/data/dataset.csv
|
138 |
+
2025-03-06 21:04 - INFO - Dataset loaded successfully.
|
139 |
+
2025-03-06 21:05 - INFO - Loading existing dataset from: src/backend/data/dataset.csv
|
140 |
+
2025-03-06 21:05 - INFO - Dataset loaded successfully.
|
141 |
+
2025-03-06 21:05 - INFO - Loading existing dataset from: src/backend/data/dataset.csv
|
142 |
+
2025-03-06 21:05 - INFO - Dataset loaded successfully.
|
143 |
+
2025-03-06 21:05 - INFO - Loading existing dataset from: src/backend/data/dataset.csv
|
144 |
+
2025-03-06 21:05 - INFO - Dataset loaded successfully.
|
145 |
+
2025-03-06 21:06 - INFO - Loading existing dataset from: src/backend/data/dataset.csv
|
146 |
+
2025-03-06 21:06 - INFO - Dataset loaded successfully.
|
147 |
+
2025-03-06 21:06 - INFO - Trying to fetch the data from database
|
148 |
+
2025-03-06 21:06 - INFO - Generated AI response for user prompt: I'm not feeling well today...
|
149 |
+
2025-03-06 21:08 - INFO - Loading existing dataset from: src/backend/data/dataset.csv
|
150 |
+
2025-03-06 21:08 - INFO - Dataset loaded successfully.
|
151 |
+
2025-03-06 21:09 - INFO - Loading existing dataset from: src/backend/data/dataset.csv
|
152 |
+
2025-03-06 21:09 - INFO - Dataset loaded successfully.
|
153 |
+
2025-03-06 21:09 - INFO - Trying to fetch the data from database
|
154 |
+
2025-03-06 21:09 - INFO - Generated AI response for user prompt: I'm not feeling well today...
|
155 |
+
2025-03-06 21:13 - INFO - Loading existing dataset from: src/backend/data/dataset.csv
|
156 |
+
2025-03-06 21:13 - INFO - Dataset loaded successfully.
|
157 |
+
2025-03-06 21:19 - INFO - Trying to fetch the data from database
|
158 |
+
2025-03-06 21:19 - INFO - Received user prompt: I'm not feeling well today
|
159 |
+
2025-03-06 21:19 - INFO - Trying to fetch the data from database
|
160 |
+
2025-03-06 21:19 - INFO - Generated AI response for user prompt: I'm not feeling well today...
|
161 |
+
2025-03-06 21:19 - INFO - Generated AI response: I'm so sorry to hear that you're not feeling well today. It can be really frustrating and worrying w...
|
162 |
+
2025-03-06 21:21 - INFO - Trying to fetch the data from database
|
163 |
+
2025-03-06 21:21 - INFO - Successfully fetched the data from database
|
164 |
+
2025-03-06 21:21 - INFO - Received user prompt: I'm not feeling well today
|
165 |
+
2025-03-06 21:21 - INFO - Trying to fetch the data from database
|
166 |
+
2025-03-06 21:21 - INFO - Successfully fetched the data from database
|
167 |
+
2025-03-06 21:21 - INFO - Generated AI response for user prompt: I'm not feeling well today...
|
168 |
+
2025-03-06 21:21 - INFO - Generated AI response: Sorry to hear that you're not feeling well today. It can be concerning when we're not at our best. S...
|
169 |
+
2025-03-06 21:47 - INFO - Received user prompt: I'm not feeling well today
|
170 |
+
2025-03-06 21:47 - INFO - Trying to fetch the data from database
|
171 |
+
2025-03-06 21:47 - INFO - Successfully fetched the data from database
|
172 |
+
2025-03-06 21:47 - INFO - Generated AI response for user prompt: I'm not feeling well today...
|
173 |
+
2025-03-06 21:47 - INFO - Generated AI response: Sorry to hear that you're not feeling well today. It's always a good idea to try to identify the pos...
|
logs/api/yuvabe_care_companion_ai_app.log
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
2025-03-06 21:45 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
2 |
+
2025-03-06 21:45 - ERROR - Error converting image to base64: [Errno 2] No such file or directory: 'src/data/images/page_icon.jpg'
|
3 |
+
2025-03-06 21:45 - INFO - user_name not found in session_state, setting to None.
|
4 |
+
2025-03-06 21:45 - INFO - user_name is None, requesting user input.
|
5 |
+
2025-03-06 21:46 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
6 |
+
2025-03-06 21:46 - INFO - user_name not found in session_state, setting to None.
|
7 |
+
2025-03-06 21:46 - INFO - user_name is None, requesting user input.
|
8 |
+
2025-03-06 21:47 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
9 |
+
2025-03-06 21:47 - INFO - user_name is None, requesting user input.
|
10 |
+
2025-03-06 21:47 - INFO - User entered name: Vela. Setting session_state.user_name.
|
11 |
+
2025-03-06 21:47 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
12 |
+
2025-03-06 21:47 - INFO - User already entered a name: Vela. Displaying greeting.
|
13 |
+
2025-03-06 21:47 - INFO - Displaying the chat history.
|
14 |
+
2025-03-06 21:47 - INFO - Waiting for user input...
|
15 |
+
2025-03-06 21:47 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
16 |
+
2025-03-06 21:47 - INFO - User already entered a name: Vela. Displaying greeting.
|
17 |
+
2025-03-06 21:47 - INFO - Displaying the chat history.
|
18 |
+
2025-03-06 21:47 - INFO - Waiting for user input...
|
19 |
+
2025-03-06 21:47 - INFO - Assistant response: Sorry to hear that you're not feeling well today. It's always a good idea to try to identify the pos...
|
20 |
+
2025-03-06 21:48 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
21 |
+
2025-03-06 21:48 - INFO - user_name not found in session_state, setting to None.
|
22 |
+
2025-03-06 21:48 - INFO - user_name is None, requesting user input.
|
23 |
+
2025-03-06 21:51 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
24 |
+
2025-03-06 21:51 - INFO - user_name not found in session_state, setting to None.
|
25 |
+
2025-03-06 21:51 - INFO - user_name is None, requesting user input.
|
26 |
+
2025-03-06 21:51 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
27 |
+
2025-03-06 21:51 - INFO - user_name not found in session_state, setting to None.
|
28 |
+
2025-03-06 21:51 - INFO - user_name is None, requesting user input.
|
29 |
+
2025-03-06 21:51 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
30 |
+
2025-03-06 21:51 - INFO - user_name is None, requesting user input.
|
31 |
+
2025-03-06 21:51 - INFO - User entered name: Velu. Setting session_state.user_name.
|
32 |
+
2025-03-06 21:51 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
33 |
+
2025-03-06 21:51 - INFO - User already entered a name: Velu. Displaying greeting.
|
34 |
+
2025-03-06 21:51 - INFO - Displaying the chat history.
|
35 |
+
2025-03-06 21:51 - INFO - Waiting for user input...
|
36 |
+
2025-03-06 21:52 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
37 |
+
2025-03-06 21:52 - INFO - User already entered a name: Velu. Displaying greeting.
|
38 |
+
2025-03-06 21:52 - INFO - Displaying the chat history.
|
39 |
+
2025-03-06 21:52 - INFO - Waiting for user input...
|
40 |
+
2025-03-06 21:53 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
41 |
+
2025-03-06 21:53 - INFO - User already entered a name: Velu. Displaying greeting.
|
42 |
+
2025-03-06 21:53 - INFO - Displaying the chat history.
|
43 |
+
2025-03-06 21:53 - INFO - Waiting for user input...
|
44 |
+
2025-03-06 21:53 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
45 |
+
2025-03-06 21:53 - INFO - User already entered a name: Velu. Displaying greeting.
|
46 |
+
2025-03-06 21:53 - INFO - Displaying the chat history.
|
47 |
+
2025-03-06 21:53 - INFO - Waiting for user input...
|
48 |
+
2025-03-06 21:53 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
49 |
+
2025-03-06 21:53 - INFO - User already entered a name: Velu. Displaying greeting.
|
50 |
+
2025-03-06 21:53 - INFO - Displaying the chat history.
|
51 |
+
2025-03-06 21:53 - INFO - Waiting for user input...
|
52 |
+
2025-03-06 21:53 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
53 |
+
2025-03-06 21:53 - INFO - User already entered a name: Velu. Displaying greeting.
|
54 |
+
2025-03-06 21:53 - INFO - Displaying the chat history.
|
55 |
+
2025-03-06 21:53 - INFO - Waiting for user input...
|
56 |
+
2025-03-06 21:53 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
57 |
+
2025-03-06 21:53 - INFO - User already entered a name: Velu. Displaying greeting.
|
58 |
+
2025-03-06 21:53 - INFO - Displaying the chat history.
|
59 |
+
2025-03-06 21:53 - INFO - Waiting for user input...
|
60 |
+
2025-03-06 21:53 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
61 |
+
2025-03-06 21:53 - INFO - user_name not found in session_state, setting to None.
|
62 |
+
2025-03-06 21:53 - INFO - user_name is None, requesting user input.
|
63 |
+
2025-03-06 21:53 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
64 |
+
2025-03-06 21:53 - INFO - user_name is None, requesting user input.
|
65 |
+
2025-03-06 21:53 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
66 |
+
2025-03-06 21:53 - INFO - user_name is None, requesting user input.
|
67 |
+
2025-03-06 21:53 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
68 |
+
2025-03-06 21:53 - INFO - user_name is None, requesting user input.
|
69 |
+
2025-03-06 21:53 - INFO - User entered name: Velu. Setting session_state.user_name.
|
70 |
+
2025-03-06 21:53 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
71 |
+
2025-03-06 21:53 - INFO - User already entered a name: Velu. Displaying greeting.
|
72 |
+
2025-03-06 21:53 - INFO - Displaying the chat history.
|
73 |
+
2025-03-06 21:53 - INFO - Waiting for user input...
|
74 |
+
2025-03-06 21:55 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
75 |
+
2025-03-06 21:55 - INFO - Page successfully configured with title: Yuvabe Care Companion AI
|
76 |
+
2025-03-06 21:55 - INFO - user_name not found in session_state, setting to None.
|
77 |
+
2025-03-06 21:55 - INFO - user_name is None, requesting user input.
|
requirements.txt
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
requests
|
3 |
+
Pillow
|
4 |
+
pandas
|
5 |
+
fastapi[standard]
|
6 |
+
pinecone
|
7 |
+
torch
|
8 |
+
torchvision
|
9 |
+
torchaudio
|
10 |
+
sentence_transformers
|
11 |
+
groq
|
12 |
+
chromadb
|
src/backend/__pycache__/main.cpython-313.pyc
ADDED
Binary file (392 Bytes). View file
|
|
src/backend/data/__pycache__/chroma_db.cpython-313.pyc
ADDED
Binary file (3.57 kB). View file
|
|
src/backend/data/__pycache__/dataset.cpython-313.pyc
ADDED
Binary file (2.56 kB). View file
|
|
src/backend/data/chroma_db.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import chromadb
|
2 |
+
from utils import logger
|
3 |
+
from chromadb.utils import embedding_functions
|
4 |
+
default_ef = embedding_functions.DefaultEmbeddingFunction()
|
5 |
+
|
6 |
+
logger = logger.get_logger()
|
7 |
+
|
8 |
+
# Constants
|
9 |
+
COLLECTION_NAME = "care_companion_ai_vectors"
|
10 |
+
DB_PATH = "vector-db"
|
11 |
+
|
12 |
+
# Initialize ChromaDB Client
|
13 |
+
client = chromadb.PersistentClient(path="src/backend/vector-db")
|
14 |
+
|
15 |
+
collection = client.get_or_create_collection(
|
16 |
+
name=COLLECTION_NAME,
|
17 |
+
embedding_function=default_ef,
|
18 |
+
metadata={
|
19 |
+
"description": "yuvabe care companion ai chroma collection",
|
20 |
+
"hnsw:space": "cosine",
|
21 |
+
"hnsw:search_ef": 100
|
22 |
+
})
|
23 |
+
|
24 |
+
def add_data_to_vector_store(df):
|
25 |
+
try:
|
26 |
+
logger.info("Started upserting the data to database")
|
27 |
+
for index, row in df.iterrows():
|
28 |
+
input_text = row['input']
|
29 |
+
output_text = row['output']
|
30 |
+
instruction_text = row['instruction']
|
31 |
+
if not isinstance(input_text, str) or not input_text.strip():
|
32 |
+
logger.warning(f"Skipping row {index} due to empty or invalid input text.")
|
33 |
+
continue
|
34 |
+
row_dict = {
|
35 |
+
"question": input_text,
|
36 |
+
"answer" : output_text,
|
37 |
+
"instruction": instruction_text
|
38 |
+
}
|
39 |
+
collection.upsert(
|
40 |
+
documents=input_text,
|
41 |
+
metadatas=row_dict,
|
42 |
+
ids=f"id{index}"
|
43 |
+
)
|
44 |
+
logger.info(f"Successfully upserted {index} records.")
|
45 |
+
logger.info("Successfully upserted all the records.")
|
46 |
+
except Exception as e:
|
47 |
+
logger.exception(f"Unable to upsert the data to the database: {e}")
|
48 |
+
|
49 |
+
def search_vector_store(query, n_result : int = 3):
|
50 |
+
try:
|
51 |
+
logger.info("Trying to fetch the data from database")
|
52 |
+
response = collection.query(
|
53 |
+
query_texts=[query],
|
54 |
+
n_results=n_result,
|
55 |
+
include=["metadatas","distances","documents"]
|
56 |
+
)
|
57 |
+
logger.info("Successfully fetched the data from database")
|
58 |
+
return response
|
59 |
+
except Exception as e:
|
60 |
+
logger.exception("Failed to fetch the data from database")
|
61 |
+
|
62 |
+
def get_retrieved_context(prompt: str) -> str:
|
63 |
+
response = search_vector_store(prompt)
|
64 |
+
if response and "metadatas" in response and response["metadatas"]:
|
65 |
+
retrieved_contexts = [metadata["answer"] for metadata in response["metadatas"][0]]
|
66 |
+
return "\n".join(retrieved_contexts[:3])
|
67 |
+
return "No relevant information found in the database."
|
src/backend/data/dataset.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import pandas as pd
|
3 |
+
import string
|
4 |
+
from utils import logger
|
5 |
+
|
6 |
+
logger = logger.get_logger()
|
7 |
+
|
8 |
+
DATASET_PATH = "src/backend/data/dataset.csv"
|
9 |
+
PARAQUET_DATASET_PATH = "hf://datasets/lavita/ChatDoctor-HealthCareMagic-100k/data/train-00000-of-00001-5e7cb295b9cff0bf.parquet"
|
10 |
+
|
11 |
+
def get_data_set():
|
12 |
+
|
13 |
+
try:
|
14 |
+
if not os.path.exists(DATASET_PATH):
|
15 |
+
logger.info(f"{DATASET_PATH} not found. Reading from Parquet file.")
|
16 |
+
df = pd.read_parquet(PARAQUET_DATASET_PATH)
|
17 |
+
df.drop_duplicates(subset=["input", "output"], inplace=True)
|
18 |
+
df.dropna(subset=["input", "output"], inplace=True) # Remove NaNs first
|
19 |
+
|
20 |
+
# This line is to remove the empty column or column with only spaces
|
21 |
+
df = df[(df["input"].str.strip() != "") & (df["output"].str.strip() != "")] # Remove empty strings/spaces
|
22 |
+
|
23 |
+
# This line is to remove puncuation and emjois
|
24 |
+
translator = str.maketrans('', '', string.punctuation)
|
25 |
+
df["input"] = df["input"].str.lower().str.translate(translator)
|
26 |
+
df["output"] = df["output"].str.lower().str.translate(translator)
|
27 |
+
df.to_csv(DATASET_PATH, index=False)
|
28 |
+
logger.info(f"CSV file created and cleaned at: {DATASET_PATH}")
|
29 |
+
else:
|
30 |
+
logger.info(f"Loading existing dataset from: {DATASET_PATH}")
|
31 |
+
df = pd.read_csv(DATASET_PATH)
|
32 |
+
logger.info("Dataset loaded successfully.")
|
33 |
+
return df
|
34 |
+
|
35 |
+
except Exception as e:
|
36 |
+
logger.error(f"Error while loading dataset: {e}", exc_info=True)
|
37 |
+
return None
|
src/backend/main.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from routes.chat_api import router
|
3 |
+
|
4 |
+
app = FastAPI()
|
5 |
+
|
6 |
+
app.include_router(router, prefix="/chat", tags=["chat"])
|
src/backend/models/__pycache__/llm_model.cpython-313.pyc
ADDED
Binary file (3.75 kB). View file
|
|
src/backend/models/__pycache__/schemas.cpython-313.pyc
ADDED
Binary file (668 Bytes). View file
|
|
src/backend/models/llm_model.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from groq import Groq
|
3 |
+
from utils import logger
|
4 |
+
from data import chroma_db
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
|
7 |
+
load_dotenv()
|
8 |
+
GROQ_KEY = os.environ.get("GROQ_API")
|
9 |
+
logger = logger.get_logger()
|
10 |
+
LOCAL_MODEL_PATH = "src/model/embedding_model.pkl"
|
11 |
+
LLM_MODEL_NAME="llama-3.3-70b-versatile"
|
12 |
+
client = Groq(api_key=GROQ_KEY)
|
13 |
+
SYSTEM_PROMPT = """You are Yuvabe Care Companion AI, an advanced healthcare assistant designed to assist users with a wide range of health-related queries. Your role includes:
|
14 |
+
|
15 |
+
- **General Medical Guidance**: Providing basic health insights (⚠️ *not a replacement for a doctor*).
|
16 |
+
- **Physiotherapy & Rehabilitation**: Advising on recovery exercises and therapy routines.
|
17 |
+
- **Mental Health Support**: Offering well-being tips and emotional health guidance.
|
18 |
+
- **Lifestyle & Wellness Advice**: Helping users with diet, sleep, and fitness recommendations.
|
19 |
+
- **Chronic Disease Management**: Educating users on managing conditions like diabetes, hypertension, etc.
|
20 |
+
- **Emergency Guidance**: Directing users on what to do in urgent medical situations (⚠️ *always recommend calling a doctor or emergency services*).
|
21 |
+
|
22 |
+
⚠️ *Important*: You are not a certified doctor. Always remind users to consult a healthcare professional for medical decisions.
|
23 |
+
"""
|
24 |
+
|
25 |
+
def get_medical_assistant_response(prompt: str):
|
26 |
+
try:
|
27 |
+
if not prompt or len(prompt.strip()) < 5:
|
28 |
+
return "⚠️ Your question seems too short. Please provide more details so I can assist you better."
|
29 |
+
|
30 |
+
response = chroma_db.search_vector_store(prompt)
|
31 |
+
|
32 |
+
if response and "metadatas" in response and response["metadatas"]:
|
33 |
+
retrieved_contexts = [metadata['answer'] for metadata in response["metadatas"][0]]
|
34 |
+
context = "\n".join(retrieved_contexts[:3])
|
35 |
+
else:
|
36 |
+
context = "No relevant information found in the database."
|
37 |
+
|
38 |
+
system_prompt = f"""
|
39 |
+
You are a helpful medical assistant. Use the provided context to answer the question as accurately as possible.
|
40 |
+
If the context is not relevant, rely on your knowledge to answer.
|
41 |
+
|
42 |
+
Context:
|
43 |
+
{context}
|
44 |
+
|
45 |
+
User Question: {prompt}
|
46 |
+
"""
|
47 |
+
|
48 |
+
chat_completion = client.chat.completions.create(
|
49 |
+
messages=[
|
50 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
51 |
+
{"role": "user", "content": system_prompt},
|
52 |
+
],
|
53 |
+
model=LLM_MODEL_NAME,
|
54 |
+
)
|
55 |
+
|
56 |
+
assistant_response = chat_completion.choices[0].message.content
|
57 |
+
logger.info(f"Generated AI response for user prompt: {prompt[:50]}...")
|
58 |
+
|
59 |
+
return assistant_response
|
60 |
+
|
61 |
+
except Exception as e:
|
62 |
+
logger.exception("Unexpected error occurred.")
|
63 |
+
return f"An error occurred while processing your request: {str(e)}"
|
src/backend/models/schemas.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pydantic import BaseModel
|
2 |
+
from typing import List,Dict, Optional
|
3 |
+
|
4 |
+
class Chat_Response(BaseModel):
|
5 |
+
prompt: Optional[str] = None
|
6 |
+
response: Optional[Dict] = None
|
src/backend/routes/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
from routes.chat_api import router
|
src/backend/routes/__pycache__/__init__.cpython-313.pyc
ADDED
Binary file (233 Bytes). View file
|
|
src/backend/routes/__pycache__/chat_api.cpython-313.pyc
ADDED
Binary file (1.51 kB). View file
|
|
src/backend/routes/chat_api.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import APIRouter, HTTPException
|
2 |
+
from utils import logger
|
3 |
+
from models.schemas import Chat_Response
|
4 |
+
from models import llm_model
|
5 |
+
|
6 |
+
logger = logger.get_logger()
|
7 |
+
router = APIRouter()
|
8 |
+
|
9 |
+
@router.post("/response")
|
10 |
+
async def get_chat_response(chat_request: Chat_Response):
|
11 |
+
try:
|
12 |
+
logger.info(f"Received user prompt: {chat_request.prompt}")
|
13 |
+
response_text = llm_model.get_medical_assistant_response(chat_request.prompt)
|
14 |
+
logger.info(f"Generated AI response: {response_text[:100]}...")
|
15 |
+
return {"status": "success", "response": response_text}
|
16 |
+
except Exception as e:
|
17 |
+
logger.exception("Unexpected error occurred while processing the request.")
|
18 |
+
raise HTTPException(status_code=500, detail="An error occurred while processing your request.")
|
src/backend/utils/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
from utils import *
|
src/backend/utils/__pycache__/__init__.cpython-313.pyc
ADDED
Binary file (210 Bytes). View file
|
|
src/backend/utils/__pycache__/logger.cpython-313.pyc
ADDED
Binary file (1.83 kB). View file
|
|
src/backend/utils/logger.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
from logging.handlers import RotatingFileHandler
|
3 |
+
import os
|
4 |
+
|
5 |
+
log_file = 'yuvabe_care_companion_ai_api.log'
|
6 |
+
log_dir = 'logs/api'
|
7 |
+
log_level=logging.INFO
|
8 |
+
|
9 |
+
def get_logger( ):
|
10 |
+
|
11 |
+
if not os.path.exists(log_dir):
|
12 |
+
os.makedirs(log_dir)
|
13 |
+
|
14 |
+
log_file_path = os.path.join(log_dir, log_file)
|
15 |
+
|
16 |
+
logger = logging.getLogger(__name__)
|
17 |
+
|
18 |
+
if not logger.hasHandlers():
|
19 |
+
logger.setLevel(log_level)
|
20 |
+
|
21 |
+
console_handler = logging.StreamHandler()
|
22 |
+
console_handler.setLevel(logging.DEBUG)
|
23 |
+
|
24 |
+
file_handler = RotatingFileHandler(log_file_path, maxBytes=5*1024*1024, backupCount=3)
|
25 |
+
file_handler.setLevel(logging.INFO)
|
26 |
+
|
27 |
+
log_format = '%(asctime)s - %(levelname)s - %(message)s'
|
28 |
+
formatter = logging.Formatter(log_format, datefmt='%Y-%m-%d %H:%M')
|
29 |
+
console_handler.setFormatter(formatter)
|
30 |
+
file_handler.setFormatter(formatter)
|
31 |
+
|
32 |
+
logger.addHandler(console_handler)
|
33 |
+
logger.addHandler(file_handler)
|
34 |
+
|
35 |
+
return logger
|
src/frontend/app/__pycache__/__init__.cpython-313.pyc
ADDED
Binary file (250 Bytes). View file
|
|
src/frontend/app/__pycache__/common_fuctions.cpython-313.pyc
ADDED
Binary file (1.77 kB). View file
|
|
src/frontend/app/__pycache__/homepage.cpython-313.pyc
ADDED
Binary file (7.34 kB). View file
|
|
src/frontend/app/common_fuctions.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import base64
|
2 |
+
import requests
|
3 |
+
from utils import logger
|
4 |
+
|
5 |
+
logger = logger.get_logger()
|
6 |
+
|
7 |
+
def img_to_base64(image_path):
|
8 |
+
"""Convert image to base64."""
|
9 |
+
try:
|
10 |
+
with open(image_path, "rb") as img_file:
|
11 |
+
return base64.b64encode(img_file.read()).decode()
|
12 |
+
except Exception as e:
|
13 |
+
logger.error(f"Error converting image to base64: {str(e)}")
|
14 |
+
return None
|
15 |
+
|
16 |
+
API_URL = "http://127.0.0.1:8000"
|
17 |
+
|
18 |
+
def get_api_response(endpoint:str, prompt: str):
|
19 |
+
try:
|
20 |
+
response = requests.post(f"{API_URL}/{endpoint}", json={"prompt": prompt})
|
21 |
+
if response.status_code == 200:
|
22 |
+
return response.json()["response"]
|
23 |
+
else:
|
24 |
+
return "An error occurred while processing your request."
|
25 |
+
except Exception as e:
|
26 |
+
return f"An error occurred while processing your request: {str(e)}"
|
src/frontend/app/homepage.py
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from utils import logger
|
3 |
+
from app import common_fuctions
|
4 |
+
|
5 |
+
logger = logger.get_logger()
|
6 |
+
|
7 |
+
PAGE_TITLE = "Yuvabe Care Companion AI"
|
8 |
+
PAGE_LAYOUT = "wide"
|
9 |
+
PAGE_ICON = "src/frontend/images/page_icon.jpg"
|
10 |
+
GITHUB_LINK = "https://github.com/Vela-Test1993/yuvabe-care-companion-ai"
|
11 |
+
ABOUT_US = "An AI-powered assistant for personalized healthcare guidance."
|
12 |
+
|
13 |
+
def get_or_greet_user_name():
|
14 |
+
if 'user_name' not in st.session_state:
|
15 |
+
st.session_state.user_name = None
|
16 |
+
logger.info("user_name not found in session_state, setting to None.")
|
17 |
+
|
18 |
+
if st.session_state.user_name is None:
|
19 |
+
logger.info("user_name is None, requesting user input.")
|
20 |
+
user_name = st.text_input("Please let me know your name:",
|
21 |
+
placeholder="Enter your name buddy")
|
22 |
+
if user_name:
|
23 |
+
st.session_state.user_name = user_name
|
24 |
+
logger.info(f"User entered name: {user_name}. Setting session_state.user_name.")
|
25 |
+
st.toast(f"Hello {st.session_state.user_name} . Welcome to {PAGE_TITLE}")
|
26 |
+
st.rerun()
|
27 |
+
else:
|
28 |
+
logger.info(f"User already entered a name: {st.session_state.user_name}. Displaying greeting.")
|
29 |
+
return st._bottom.subheader(f"Hello {st.session_state.user_name}! How can I assist you today?")
|
30 |
+
|
31 |
+
def display_chat():
|
32 |
+
logger.info("Displaying the chat history.")
|
33 |
+
if "messages" not in st.session_state:
|
34 |
+
st.session_state.messages = []
|
35 |
+
for message in st.session_state.messages:
|
36 |
+
with st.chat_message(message["role"]):
|
37 |
+
st.markdown(message["content"])
|
38 |
+
logger.info(f"Displayed {len(st.session_state.messages)} messages from the chat history.")
|
39 |
+
|
40 |
+
def handle_user_input():
|
41 |
+
"""
|
42 |
+
Handles user input for Yuvabe Care Companion AI, validates query relevance,
|
43 |
+
and fetches a response from the medical assistant model.
|
44 |
+
"""
|
45 |
+
|
46 |
+
logger.info("Waiting for user input...")
|
47 |
+
|
48 |
+
prompt = st.chat_input("Ask me anything about health, physiotherapy, or medical advice!")
|
49 |
+
|
50 |
+
if prompt:
|
51 |
+
|
52 |
+
with st.chat_message("user"):
|
53 |
+
st.markdown(prompt)
|
54 |
+
|
55 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
56 |
+
|
57 |
+
try:
|
58 |
+
with st.spinner("Processing your query..."):
|
59 |
+
try:
|
60 |
+
response = common_fuctions.get_api_response("/chat/response", prompt)
|
61 |
+
except Exception as e:
|
62 |
+
logger.error(f"AI response generation failed: {str(e)}")
|
63 |
+
response = "⚠️ Sorry, I couldn't process your request. Please try again later."
|
64 |
+
except Exception as e:
|
65 |
+
logger.exception("Error during similarity check or response generation.")
|
66 |
+
response = "⚠️ Oops! Something went wrong. Please try again."
|
67 |
+
|
68 |
+
with st.chat_message("assistant"):
|
69 |
+
st.markdown(response)
|
70 |
+
|
71 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
72 |
+
|
73 |
+
logger.info(f"Assistant response: {response[:100]}...")
|
74 |
+
|
75 |
+
def config_homepage():
|
76 |
+
st.set_page_config(
|
77 |
+
page_title=PAGE_TITLE,
|
78 |
+
page_icon= PAGE_ICON,
|
79 |
+
layout=PAGE_LAYOUT,
|
80 |
+
initial_sidebar_state="auto",
|
81 |
+
menu_items={"Get help":GITHUB_LINK,
|
82 |
+
"Report a bug": GITHUB_LINK,
|
83 |
+
"About": ABOUT_US}
|
84 |
+
)
|
85 |
+
|
86 |
+
st.markdown(f"""
|
87 |
+
<h1 style="color: darkblue; text-align: left; font-size: 50px;">
|
88 |
+
<i>{PAGE_TITLE} 🏥⚕️🤖</i>
|
89 |
+
</h1>
|
90 |
+
""", unsafe_allow_html=True
|
91 |
+
)
|
92 |
+
|
93 |
+
logger.info(f"Page successfully configured with title: {PAGE_TITLE}")
|
94 |
+
st.session_state.config_status = False
|
95 |
+
|
96 |
+
def setup_homepage():
|
97 |
+
st.set_page_config(
|
98 |
+
page_title=PAGE_TITLE,
|
99 |
+
page_icon= PAGE_ICON,
|
100 |
+
layout=PAGE_LAYOUT,
|
101 |
+
initial_sidebar_state="auto",
|
102 |
+
menu_items={"Get help":GITHUB_LINK,
|
103 |
+
"Report a bug": GITHUB_LINK,
|
104 |
+
"About": ABOUT_US}
|
105 |
+
)
|
106 |
+
|
107 |
+
st.markdown(f"""
|
108 |
+
<h1 style="color: darkblue; text-align: left; font-size: 50px;">
|
109 |
+
<i>{PAGE_TITLE} 🏥⚕️🤖</i>
|
110 |
+
</h1>
|
111 |
+
""", unsafe_allow_html=True
|
112 |
+
)
|
113 |
+
|
114 |
+
logger.info(f"Page successfully configured with title: {PAGE_TITLE}")
|
115 |
+
st.session_state.config_status = False
|
116 |
+
|
117 |
+
st.markdown("<hr>", unsafe_allow_html=True) # To add a Horizontal line below title
|
118 |
+
|
119 |
+
img_base64 = common_fuctions.img_to_base64(PAGE_ICON)
|
120 |
+
|
121 |
+
if img_base64:
|
122 |
+
st.sidebar.markdown(
|
123 |
+
f'<img src="data:image/png;base64,{img_base64}" class="cover-glow">',
|
124 |
+
unsafe_allow_html=True,
|
125 |
+
)
|
126 |
+
|
127 |
+
st.sidebar.markdown("---")
|
128 |
+
|
129 |
+
if get_or_greet_user_name():
|
130 |
+
|
131 |
+
display_chat()
|
132 |
+
|
133 |
+
handle_user_input()
|
src/frontend/home.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from app import homepage
|
2 |
+
|
3 |
+
homepage.setup_homepage()
|
4 |
+
|
src/frontend/images/page_icon.jpg
ADDED
![]() |
src/frontend/pages/database_response_page.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from app import homepage
|
2 |
+
|
3 |
+
homepage.config_homepage()
|
src/frontend/utils/__pycache__/logger.cpython-313.pyc
ADDED
Binary file (1.83 kB). View file
|
|
src/frontend/utils/logger.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
from logging.handlers import RotatingFileHandler
|
3 |
+
import os
|
4 |
+
|
5 |
+
log_file = 'yuvabe_care_companion_ai_app.log'
|
6 |
+
log_dir = 'logs/api'
|
7 |
+
log_level=logging.INFO
|
8 |
+
|
9 |
+
def get_logger( ):
|
10 |
+
|
11 |
+
if not os.path.exists(log_dir):
|
12 |
+
os.makedirs(log_dir)
|
13 |
+
|
14 |
+
log_file_path = os.path.join(log_dir, log_file)
|
15 |
+
|
16 |
+
logger = logging.getLogger(__name__)
|
17 |
+
|
18 |
+
if not logger.hasHandlers():
|
19 |
+
logger.setLevel(log_level)
|
20 |
+
|
21 |
+
console_handler = logging.StreamHandler()
|
22 |
+
console_handler.setLevel(logging.DEBUG)
|
23 |
+
|
24 |
+
file_handler = RotatingFileHandler(log_file_path, maxBytes=5*1024*1024, backupCount=3)
|
25 |
+
file_handler.setLevel(logging.INFO)
|
26 |
+
|
27 |
+
log_format = '%(asctime)s - %(levelname)s - %(message)s'
|
28 |
+
formatter = logging.Formatter(log_format, datefmt='%Y-%m-%d %H:%M')
|
29 |
+
console_handler.setFormatter(formatter)
|
30 |
+
file_handler.setFormatter(formatter)
|
31 |
+
|
32 |
+
logger.addHandler(console_handler)
|
33 |
+
logger.addHandler(file_handler)
|
34 |
+
|
35 |
+
return logger
|