Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- .gitattributes +35 -35
- .gitignore +153 -0
- Dockerfile +16 -0
- README.md +11 -11
- main.py +339 -0
- requirements.txt +8 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,35 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
##########################
|
| 2 |
+
# KEDRO PROJECT
|
| 3 |
+
|
| 4 |
+
# ignore all local configuration
|
| 5 |
+
conf/local/**
|
| 6 |
+
!conf/local/.gitkeep
|
| 7 |
+
venv
|
| 8 |
+
# ignore potentially sensitive credentials files
|
| 9 |
+
conf/**/*credentials*
|
| 10 |
+
|
| 11 |
+
# ignore everything in the following folders
|
| 12 |
+
data/live
|
| 13 |
+
data/preprocesssed
|
| 14 |
+
data/raw
|
| 15 |
+
# except their sub-folders
|
| 16 |
+
|
| 17 |
+
#image_app/artifacts/
|
| 18 |
+
# also keep all .gitkeep files
|
| 19 |
+
!.gitkeep
|
| 20 |
+
|
| 21 |
+
# keep also the example dataset
|
| 22 |
+
!data/01_raw/*
|
| 23 |
+
|
| 24 |
+
mlruns/
|
| 25 |
+
##########################
|
| 26 |
+
# Common files
|
| 27 |
+
|
| 28 |
+
# IntelliJ
|
| 29 |
+
.idea/
|
| 30 |
+
*.iml
|
| 31 |
+
out/
|
| 32 |
+
.idea_modules/
|
| 33 |
+
|
| 34 |
+
### macOS
|
| 35 |
+
*.DS_Store
|
| 36 |
+
.AppleDouble
|
| 37 |
+
.LSOverride
|
| 38 |
+
.Trashes
|
| 39 |
+
|
| 40 |
+
# Vim
|
| 41 |
+
*~
|
| 42 |
+
.*.swo
|
| 43 |
+
.*.swp
|
| 44 |
+
|
| 45 |
+
# emacs
|
| 46 |
+
*~
|
| 47 |
+
\#*\#
|
| 48 |
+
/.emacs.desktop
|
| 49 |
+
/.emacs.desktop.lock
|
| 50 |
+
*.elc
|
| 51 |
+
|
| 52 |
+
# JIRA plugin
|
| 53 |
+
atlassian-ide-plugin.xml
|
| 54 |
+
|
| 55 |
+
# C extensions
|
| 56 |
+
*.so
|
| 57 |
+
|
| 58 |
+
### Python template
|
| 59 |
+
# Byte-compiled / optimized / DLL files
|
| 60 |
+
__pycache__/
|
| 61 |
+
*.py[cod]
|
| 62 |
+
*$py.class
|
| 63 |
+
|
| 64 |
+
# Distribution / packaging
|
| 65 |
+
.Python
|
| 66 |
+
build/
|
| 67 |
+
develop-eggs/
|
| 68 |
+
dist/
|
| 69 |
+
downloads/
|
| 70 |
+
eggs/
|
| 71 |
+
.eggs/
|
| 72 |
+
lib/
|
| 73 |
+
lib64/
|
| 74 |
+
parts/
|
| 75 |
+
sdist/
|
| 76 |
+
var/
|
| 77 |
+
wheels/
|
| 78 |
+
*.egg-info/
|
| 79 |
+
.installed.cfg
|
| 80 |
+
*.egg
|
| 81 |
+
MANIFEST
|
| 82 |
+
|
| 83 |
+
# PyInstaller
|
| 84 |
+
# Usually these files are written by a python script from a template
|
| 85 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 86 |
+
*.manifest
|
| 87 |
+
*.spec
|
| 88 |
+
|
| 89 |
+
# Installer logs
|
| 90 |
+
pip-log.txt
|
| 91 |
+
pip-delete-this-directory.txt
|
| 92 |
+
|
| 93 |
+
# Unit test / coverage reports
|
| 94 |
+
htmlcov/
|
| 95 |
+
.tox/
|
| 96 |
+
.coverage
|
| 97 |
+
.coverage.*
|
| 98 |
+
.cache
|
| 99 |
+
nosetests.xml
|
| 100 |
+
coverage.xml
|
| 101 |
+
*.cover
|
| 102 |
+
.hypothesis/
|
| 103 |
+
|
| 104 |
+
# Translations
|
| 105 |
+
*.mo
|
| 106 |
+
*.pot
|
| 107 |
+
|
| 108 |
+
# Django stuff:
|
| 109 |
+
*.log
|
| 110 |
+
.static_storage/
|
| 111 |
+
.media/
|
| 112 |
+
local_settings.py
|
| 113 |
+
|
| 114 |
+
# Flask stuff:
|
| 115 |
+
instance/
|
| 116 |
+
.webassets-cache
|
| 117 |
+
|
| 118 |
+
# Scrapy stuff:
|
| 119 |
+
.scrapy
|
| 120 |
+
|
| 121 |
+
# Sphinx documentation
|
| 122 |
+
docs/_build/
|
| 123 |
+
|
| 124 |
+
# PyBuilder
|
| 125 |
+
target/
|
| 126 |
+
|
| 127 |
+
# Jupyter Notebook
|
| 128 |
+
.ipynb_checkpoints
|
| 129 |
+
|
| 130 |
+
# pyenv
|
| 131 |
+
.python-version
|
| 132 |
+
|
| 133 |
+
# celery beat schedule file
|
| 134 |
+
celerybeat-schedule
|
| 135 |
+
|
| 136 |
+
# SageMath parsed files
|
| 137 |
+
*.sage.py
|
| 138 |
+
|
| 139 |
+
# Environments
|
| 140 |
+
.env
|
| 141 |
+
.venv
|
| 142 |
+
env/
|
| 143 |
+
venv/
|
| 144 |
+
ENV/
|
| 145 |
+
env.bak/
|
| 146 |
+
venv.bak/
|
| 147 |
+
|
| 148 |
+
# mkdocs documentation
|
| 149 |
+
/site
|
| 150 |
+
|
| 151 |
+
# mypy
|
| 152 |
+
.mypy_cache/
|
| 153 |
+
|
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9.19-slim-bullseye
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY . /app
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
|
| 9 |
+
|
| 10 |
+
RUN --mount=type=secret,id=GROQ,mode=0444,required=true
|
| 11 |
+
|
| 12 |
+
RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true
|
| 13 |
+
|
| 14 |
+
EXPOSE 8501
|
| 15 |
+
|
| 16 |
+
CMD ["streamlit","run","main.py"]
|
README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: TherepyBot
|
| 3 |
-
emoji: 😻
|
| 4 |
-
colorFrom: indigo
|
| 5 |
-
colorTo: green
|
| 6 |
-
sdk: docker
|
| 7 |
-
pinned: false
|
| 8 |
-
license: apache-2.0
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: TherepyBot
|
| 3 |
+
emoji: 😻
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
license: apache-2.0
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
main.py
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
from langchain_community.document_loaders import WebBaseLoader
|
| 4 |
+
from langchain_community.embeddings import OllamaEmbeddings
|
| 5 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 6 |
+
from langchain_core.messages import AIMessage, HumanMessage
|
| 7 |
+
from langchain.chains.combine_documents import create_stuff_documents_chain
|
| 8 |
+
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
| 9 |
+
from langchain_community.chat_message_histories import ChatMessageHistory
|
| 10 |
+
from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings
|
| 11 |
+
from langchain_core.chat_history import BaseChatMessageHistory
|
| 12 |
+
from langchain.chains import create_history_aware_retriever, create_retrieval_chain
|
| 13 |
+
from langchain.retrievers import EnsembleRetriever
|
| 14 |
+
from langchain_community.retrievers import BM25Retriever
|
| 15 |
+
from langchain_community.vectorstores import FAISS
|
| 16 |
+
from langchain_groq import ChatGroq
|
| 17 |
+
from dotenv import load_dotenv
|
| 18 |
+
from langchain_community.embeddings import OllamaEmbeddings
|
| 19 |
+
import time
|
| 20 |
+
import pprint
|
| 21 |
+
from langchain_core.runnables.history import RunnableWithMessageHistory
|
| 22 |
+
import json
|
| 23 |
+
import os
|
| 24 |
+
from langchain_community.chat_models import ChatOllama
|
| 25 |
+
load_dotenv()
|
| 26 |
+
|
| 27 |
+
qroq_key = os.environ['GROQ']
|
| 28 |
+
hf_key = os.environ['HF_TOKEN']
|
| 29 |
+
#Creating LLM
|
| 30 |
+
qroq_key = os.environ.get('GROQ')
|
| 31 |
+
hf_key = os.environ.get('HF_TOKEN')
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
llm_groq = ChatGroq(api_key=qroq_key, model='llama3-8b-8192')
|
| 35 |
+
#llm_ollama = ChatOllama(model='llama3.1:8b-instruct-q2_K', num_gpu=2)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
hf_embeddings = HuggingFaceInferenceAPIEmbeddings(api_key=hf_key, model_name="sentence-transformers/all-MiniLM-L12-v2")
|
| 39 |
+
#ollama_embeddings = OllamaEmbeddings(model="nomic-embed-text:latest",num_gpu=1)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
#Links to add docs from
|
| 43 |
+
|
| 44 |
+
links1 = [
|
| 45 |
+
"https://wiki.healthygamer.gg/en/Self-Improvement",
|
| 46 |
+
"https://wiki.healthygamer.gg/en/Motivation",
|
| 47 |
+
"https://wiki.healthygamer.gg/en/Depression",
|
| 48 |
+
"https://wiki.healthygamer.gg/en/Anxiety",
|
| 49 |
+
"https://wiki.healthygamer.gg/en/Stress",
|
| 50 |
+
"https://wiki.healthygamer.gg/en/Failure",
|
| 51 |
+
"https://wiki.healthygamer.gg/en/Mental_Health",
|
| 52 |
+
"https://wiki.healthygamer.gg/en/Social_Anxiety",
|
| 53 |
+
"https://wiki.healthygamer.gg/en/Confidence",
|
| 54 |
+
"https://wiki.healthygamer.gg/en/Loneliness",
|
| 55 |
+
"https://wiki.healthygamer.gg/en/Insecurity",
|
| 56 |
+
"https://wiki.healthygamer.gg/en/Intrusive_Thoughts",
|
| 57 |
+
"https://wiki.healthygamer.gg/en/Emotions",
|
| 58 |
+
"https://wiki.healthygamer.gg/en/Imposter_Syndrome",
|
| 59 |
+
"https://wiki.healthygamer.gg/en/Samskaras",
|
| 60 |
+
"https://wiki.healthygamer.gg/en/Addiction",
|
| 61 |
+
"https://wiki.healthygamer.gg/en/Video_Game_Addiction",
|
| 62 |
+
"https://wiki.healthygamer.gg/en/Borderline_Personality_Disorder",
|
| 63 |
+
"https://wiki.healthygamer.gg/en/Personality",
|
| 64 |
+
"https://wiki.healthygamer.gg/en/Personality",
|
| 65 |
+
"https://wiki.healthygamer.gg/en/Relationships",
|
| 66 |
+
"https://wiki.healthygamer.gg/en/Communication",
|
| 67 |
+
"https://wiki.healthygamer.gg/en/Psychology",
|
| 68 |
+
"https://wiki.healthygamer.gg/en/Learning",
|
| 69 |
+
"https://wiki.healthygamer.gg/en/Productivity",
|
| 70 |
+
"https://wiki.healthygamer.gg/en/Career",
|
| 71 |
+
"https://wiki.healthygamer.gg/en/Spirituality",
|
| 72 |
+
"https://wiki.healthygamer.gg/en/Dharma",
|
| 73 |
+
"https://wiki.healthygamer.gg/en/Karma",
|
| 74 |
+
"https://wiki.healthygamer.gg/en/Suffering",
|
| 75 |
+
"https://wiki.healthygamer.gg/en/Meditation",
|
| 76 |
+
"https://wiki.healthygamer.gg/en/Meditation_Techniques",
|
| 77 |
+
"https://wiki.healthygamer.gg/en/Ayurveda",
|
| 78 |
+
"https://wiki.healthygamer.gg/en/Vata",
|
| 79 |
+
"https://wiki.healthygamer.gg/en/Pitta",
|
| 80 |
+
"https://wiki.healthygamer.gg/en/Kapha",
|
| 81 |
+
|
| 82 |
+
"https://neurosciencenews.com/empathy-logic-wisdom-27581/",
|
| 83 |
+
"https://neurosciencenews.com/placebo-stress-anxiety-27576/",
|
| 84 |
+
"https://neurosciencenews.com/memory-alcohol-use-27574/",
|
| 85 |
+
"https://neurosciencenews.com/psychosis-cognitive-network-27571/",
|
| 86 |
+
"https://neurosciencenews.com/psilocybin-antidepressant-psychopharmacology-27567/",
|
| 87 |
+
"https://neurosciencenews.com/childhood-inflammation-mental-health-27566/",
|
| 88 |
+
"https://neurosciencenews.com/neuroticism-self-control-27565/",
|
| 89 |
+
"https://neurosciencenews.com/digital-swiping-boredom-27560/",
|
| 90 |
+
"https://neurosciencenews.com/psychology-death-disaster-27552/",
|
| 91 |
+
"https://neurosciencenews.com/moral-values-seasons-psychology-37540/",
|
| 92 |
+
"https://neurosciencenews.com/classical-music-depression-sync-brain-27538/",
|
| 93 |
+
"https://neurosciencenews.com/knowlege-group-welfare-psychology-27535/",
|
| 94 |
+
"https://neurosciencenews.com/loneliness-nightmares-psychology-27522/",
|
| 95 |
+
"https://neurosciencenews.com/mental-effort-stress-27515/",
|
| 96 |
+
"https://neurosciencenews.com/happiness-psychology-satisfaction-27514/",
|
| 97 |
+
"https://neurosciencenews.com/environment-genetics-schizophrenia-27511/",
|
| 98 |
+
"https://neurosciencenews.com/exercise-motivation-depression-27495/",
|
| 99 |
+
"https://neurosciencenews.com/curiosity-memory-neurodevelopment-27584/",
|
| 100 |
+
"https://neurosciencenews.com/neuroinflammation-long-covid-27586/",
|
| 101 |
+
"https://neurosciencenews.com/visual-object-memory-neuroscience-27585/",
|
| 102 |
+
"https://neurosciencenews.com/non-cognitive-intelligence-27582/",
|
| 103 |
+
"https://neurosciencenews.com/love-brain-neuroscience-27581/",
|
| 104 |
+
"https://neurosciencenews.com/kyrurenine-pathway-alzheimers-memory-27579/",
|
| 105 |
+
"https://neurosciencenews.com/bipolar-mental-health-26296/",
|
| 106 |
+
"https://neurosciencenews.com/asd-genetics-sleep-bipolar-26233/",
|
| 107 |
+
"https://neurosciencenews.com/bartonella-psychosis-genetics-26267/",
|
| 108 |
+
"https://neurosciencenews.com/psychosis-brain-systems-25910/",
|
| 109 |
+
"https://neurosciencenews.com/genetic-left-handed-neurology-25864/",
|
| 110 |
+
"https://www.psychologytoday.com/us/blog/the-mysteries-of-love/202408/understanding-chronic-loneliness-in-adolescence",
|
| 111 |
+
"https://www.psychologytoday.com/us/blog/the-happiness-project/201702/7-types-loneliness-and-why-it-matters",
|
| 112 |
+
"https://www.psychologytoday.com/us/blog/the-path-to-passionate-happiness/202407/why-are-we-so-lonely",
|
| 113 |
+
"https://www.psychologytoday.com/us/blog/a-unified-theory-of-happiness/201612/5-ways-to-cope-with-ostracism",
|
| 114 |
+
"https://www.psychologytoday.com/us/blog/the-mysteries-of-love/202408/why-we-crave-unrequited-love-the-allure-of-the-unavailable",
|
| 115 |
+
"https://www.psychologytoday.com/us/blog/social-instincts/202404/the-concerning-global-rise-in-hikikomori-syndrome-explained",
|
| 116 |
+
"https://www.psychologytoday.com/us/blog/are-we-done-fighting/202408/the-fine-line-between-confidence-and-closed-mindedness",
|
| 117 |
+
"https://www.psychologytoday.com/us/blog/the-attraction-doctor/202408/behaviors-that-signal-romantic-or-sexual-interest",
|
| 118 |
+
"https://www.psychologytoday.com/us/blog/living-with-emotional-intensity/202408/the-rollercoaster-of-love-growing-up-with-an-unstable"
|
| 119 |
+
"https://www.psychologytoday.com/us/basics/addiction",
|
| 120 |
+
"https://www.psychologytoday.com/us/basics/anxiety",
|
| 121 |
+
"https://www.psychologytoday.com/us/basics/adhd",
|
| 122 |
+
"https://www.psychologytoday.com/us/basics/aspergers-syndrome",
|
| 123 |
+
"https://www.psychologytoday.com/us/basics/autism",
|
| 124 |
+
"https://www.psychologytoday.com/us/basics/bipolar-disorder",
|
| 125 |
+
"https://www.psychologytoday.com/us/basics/chronic-pain",
|
| 126 |
+
"https://www.psychologytoday.com/us/basics/depression",
|
| 127 |
+
"https://www.psychologytoday.com/us/basics/eating-disorders",
|
| 128 |
+
"https://www.psychologytoday.com/us/basics/passive-aggression",
|
| 129 |
+
"https://www.psychologytoday.com/us/basics/personality",
|
| 130 |
+
"https://www.psychologytoday.com/us/basics/shyness",
|
| 131 |
+
"https://www.psychologytoday.com/us/basics/motivation",
|
| 132 |
+
"https://www.psychologytoday.com/us/basics/happiness",
|
| 133 |
+
"https://www.psychologytoday.com/us/basics/positive-psychology",
|
| 134 |
+
"https://www.psychologytoday.com/us/basics/smoking",
|
| 135 |
+
"https://www.psychologytoday.com/us/basics/low-sexual-desire",
|
| 136 |
+
"https://www.psychologytoday.com/us/basics/relationships",
|
| 137 |
+
"https://www.psychologytoday.com/us/basics/sex",
|
| 138 |
+
"https://www.psychologytoday.com/us/basics/child-development",
|
| 139 |
+
"https://www.psychologytoday.com/us/basics/parenting",
|
| 140 |
+
"https://www.psychologytoday.com/us/conditions/tinnitus",
|
| 141 |
+
"https://www.psychologytoday.com/us/blog/the-mysteries-of-love/202408/are-you-secretly-being-controlled-by-tone-or-nonverbal-cues",
|
| 142 |
+
"https://www.psychologytoday.com/us/blog/the-attraction-doctor/202406/why-people-manipulate-and-play-games-in-relationships",
|
| 143 |
+
"https://www.psychologytoday.com/us/blog/the-attraction-doctor/202405/3-flirting-errors-are-you-a-bad-flirt-and-dont-know-it",
|
| 144 |
+
"https://www.psychologytoday.com/us/blog/the-attraction-doctor/202403/how-do-nice-guys-and-gals-finish-first",
|
| 145 |
+
"https://www.psychologytoday.com/us/blog/a-funny-bone-to-pick/202406/pebbling-a-new-term-for-an-established-dating-trend",
|
| 146 |
+
"https://www.psychologytoday.com/us/blog/magnetic-partners/201608/how-couples-deal-with-the-loss-of-physical-attraction",
|
| 147 |
+
"https://www.psychologytoday.com/us/blog/the-state-of-our-unions/202208/whats-behind-the-rise-of-lonely-single-men",
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
]
|
| 153 |
+
|
| 154 |
+
links2 =["https://www.psychologytoday.com/us/blog/the-mysteries-of-love/202408/understanding-chronic-loneliness-in-adolescence",""
|
| 155 |
+
"https://www.psychologytoday.com/us/blog/the-happiness-project/201702/7-types-loneliness-and-why-it-matters",
|
| 156 |
+
"https://www.psychologytoday.com/us/blog/the-path-to-passionate-happiness/202407/why-are-we-so-lonely",
|
| 157 |
+
"https://www.psychologytoday.com/us/blog/a-unified-theory-of-happiness/201612/5-ways-to-cope-with-ostracism",
|
| 158 |
+
"https://www.psychologytoday.com/us/blog/the-mysteries-of-love/202408/why-we-crave-unrequited-love-the-allure-of-the-unavailable",
|
| 159 |
+
"https://www.psychologytoday.com/us/blog/social-instincts/202404/the-concerning-global-rise-in-hikikomori-syndrome-explained",
|
| 160 |
+
"https://www.psychologytoday.com/us/blog/are-we-done-fighting/202408/the-fine-line-between-confidence-and-closed-mindedness",
|
| 161 |
+
"https://www.psychologytoday.com/us/blog/the-attraction-doctor/202408/behaviors-that-signal-romantic-or-sexual-interest",
|
| 162 |
+
"https://www.psychologytoday.com/us/blog/living-with-emotional-intensity/202408/the-rollercoaster-of-love-growing-up-with-an-unstable"
|
| 163 |
+
]
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
#initialize splitter
|
| 168 |
+
splitter = RecursiveCharacterTextSplitter(chunk_size=1000,chunk_overlap=200)
|
| 169 |
+
file_path = 'index2'
|
| 170 |
+
|
| 171 |
+
#create docs using webbase loader
|
| 172 |
+
def links_to_docs(links: list):
|
| 173 |
+
loader = WebBaseLoader(web_path=links1)
|
| 174 |
+
all_docs = loader.load()
|
| 175 |
+
split_docs = splitter.split_documents(all_docs) #need to savve split docs
|
| 176 |
+
return split_docs
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def vector_store(chunks, embedding_model):
|
| 180 |
+
if os.path.exists('./index_local'):
|
| 181 |
+
store = FAISS.load_local("index_local",embeddings=embedding_model, allow_dangerous_deserialization=True)
|
| 182 |
+
else:
|
| 183 |
+
store = FAISS.from_documents(chunks, embedding_model)
|
| 184 |
+
store.save_local('index_local')
|
| 185 |
+
return store
|
| 186 |
+
|
| 187 |
+
##vector store not saving anything as an object
|
| 188 |
+
if 'msg_store' not in st.session_state:
|
| 189 |
+
st.session_state.chunks = links_to_docs(links=links1)
|
| 190 |
+
st.session_state.embeddings = hf_embeddings
|
| 191 |
+
st.session_state.vector_store = vector_store(chunks=st.session_state.chunks, embedding_model=st.session_state.embeddings)
|
| 192 |
+
st.session_state.normal_ret = st.session_state.vector_store.as_retriever(search_kwargs= {"k":10})
|
| 193 |
+
st.session_state.keyword_ret = BM25Retriever.from_documents(st.session_state.chunks)
|
| 194 |
+
st.session_state.ensemble_ret = EnsembleRetriever(retrievers=[st.session_state.normal_ret,st.session_state.keyword_ret],weights=[0.75, 0.25])
|
| 195 |
+
st.session_state.secret_id = "abc123"
|
| 196 |
+
#manages msg history
|
| 197 |
+
st.session_state.msg_store = {}
|
| 198 |
+
print('--'*100)
|
| 199 |
+
|
| 200 |
+
if 'msg_list' not in st.session_state:
|
| 201 |
+
st.session_state.msg_list = []
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
###creating history aware retrieval
|
| 205 |
+
|
| 206 |
+
contextualize_q_system_prompt = (
|
| 207 |
+
"Given a chat history and the latest user question "
|
| 208 |
+
"which might reference context in the chat history, "
|
| 209 |
+
"sum up the chat history in 300 words"
|
| 210 |
+
"without the chat history. Do NOT answer the question,"
|
| 211 |
+
"just reformulate it if needed and otherwise return it as is."
|
| 212 |
+
|
| 213 |
+
)
|
| 214 |
+
|
| 215 |
+
contextualize_q_prompt = ChatPromptTemplate.from_messages(
|
| 216 |
+
[
|
| 217 |
+
("system", contextualize_q_system_prompt),
|
| 218 |
+
MessagesPlaceholder("chat_history"),
|
| 219 |
+
("human", "{input}"),
|
| 220 |
+
]
|
| 221 |
+
)
|
| 222 |
+
|
| 223 |
+
history_aware_retriever = create_history_aware_retriever(
|
| 224 |
+
llm_groq, st.session_state.ensemble_ret, contextualize_q_prompt
|
| 225 |
+
)
|
| 226 |
+
|
| 227 |
+
system_prompt = (
|
| 228 |
+
"""
|
| 229 |
+
Answer the questions based on the provided context only.
|
| 230 |
+
Please provide the most accurate response based on the question,
|
| 231 |
+
avoid words "HealthyGamer Wiki","gamer", or "Wiki","psychologytoday",
|
| 232 |
+
or any "article",
|
| 233 |
+
or any reference to Healthy Gamer,
|
| 234 |
+
'also never explicitly say "HealthyGamer Wiki","gamer", or "Wiki",
|
| 235 |
+
also keep the chat history in context
|
| 236 |
+
"{context}"
|
| 237 |
+
"""
|
| 238 |
+
)
|
| 239 |
+
qa_prompt = ChatPromptTemplate.from_messages(
|
| 240 |
+
[
|
| 241 |
+
("system", system_prompt),
|
| 242 |
+
MessagesPlaceholder("chat_history"),
|
| 243 |
+
("human", "{input}"),
|
| 244 |
+
]
|
| 245 |
+
)
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
question_answer_chain = create_stuff_documents_chain(llm_groq, qa_prompt)
|
| 250 |
+
|
| 251 |
+
rag_chain = create_retrieval_chain(history_aware_retriever, question_answer_chain)
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def get_session_history(session_id: str) -> BaseChatMessageHistory:
|
| 255 |
+
if session_id not in st.session_state.msg_store :
|
| 256 |
+
st.session_state.msg_store[session_id] = ChatMessageHistory()
|
| 257 |
+
return st.session_state.msg_store[session_id]
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
conversational_rag_chain = RunnableWithMessageHistory(
|
| 261 |
+
rag_chain,
|
| 262 |
+
get_session_history,
|
| 263 |
+
input_messages_key="input",
|
| 264 |
+
history_messages_key="chat_history",
|
| 265 |
+
output_messages_key="answer",
|
| 266 |
+
)
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
def get_response(userquery:str):
|
| 270 |
+
|
| 271 |
+
rag_response = conversational_rag_chain.invoke(
|
| 272 |
+
{"input": userquery},
|
| 273 |
+
config={
|
| 274 |
+
"configurable": {"session_id": "abc123"}
|
| 275 |
+
},
|
| 276 |
+
)["answer"]
|
| 277 |
+
|
| 278 |
+
return rag_response
|
| 279 |
+
|
| 280 |
+
##creating streamlit frontend now
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
st.title("Calm Counsel")
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
history = get_session_history(st.session_state.secret_id)
|
| 287 |
+
|
| 288 |
+
user_query = st.chat_input("Type your message here...")
|
| 289 |
+
sequence_number = 0
|
| 290 |
+
if user_query is not None and user_query != "":
|
| 291 |
+
|
| 292 |
+
for msg in st.session_state.msg_list:
|
| 293 |
+
with st.chat_message(msg['role']):
|
| 294 |
+
st.markdown(msg['content'])
|
| 295 |
+
|
| 296 |
+
user_query_backup = user_query
|
| 297 |
+
#history.add_message(HumanMessage(content=user_query))
|
| 298 |
+
|
| 299 |
+
print('x'*100)
|
| 300 |
+
#print(st.session_state.msg_list)
|
| 301 |
+
|
| 302 |
+
with st.chat_message("human"):
|
| 303 |
+
st.markdown(user_query)
|
| 304 |
+
|
| 305 |
+
#adding user query to st history
|
| 306 |
+
st.session_state.msg_list.append({'role':'human','content':user_query})
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
#trying for dict to json
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
#get ai response
|
| 314 |
+
with st.spinner("Thinking..."):
|
| 315 |
+
response = get_response(user_query)
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
#display ai response
|
| 319 |
+
|
| 320 |
+
with st.chat_message("ai"):
|
| 321 |
+
st.markdown(response)
|
| 322 |
+
|
| 323 |
+
print(st.session_state.msg_list)
|
| 324 |
+
|
| 325 |
+
st.session_state.msg_list.append({'role':'ai','content':response})
|
| 326 |
+
print('Ii' * 100)
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
print('Mm' * 100)
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
langchain
|
| 2 |
+
langchain-community
|
| 3 |
+
langchain-groq
|
| 4 |
+
streamlit
|
| 5 |
+
python-dotenv
|
| 6 |
+
beautifulsoup4
|
| 7 |
+
faiss-cpu
|
| 8 |
+
rank-bm25
|