jiyamary1 commited on
Commit
77f76f2
Β·
1 Parent(s): a1f5a79

files added

Browse files
Files changed (5) hide show
  1. .gitignore +174 -0
  2. LICENSE +21 -0
  3. app.py +100 -0
  4. chatbot_ui.html +44 -0
  5. requirements.txt +4 -0
.gitignore ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Ruff stuff:
171
+ .ruff_cache/
172
+
173
+ # PyPI configuration file
174
+ .pypirc
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jiya Mary Joseph
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from llama_cpp import Llama
3
+ from dotenv import load_dotenv
4
+ import os
5
+
6
+ # Load environment variables
7
+ load_dotenv()
8
+ print(f"REPO_ID: {os.getenv('REPO_ID')}")
9
+
10
+ # Load Llama model
11
+ llm = Llama.from_pretrained(
12
+ repo_id=os.getenv("REPO_ID"),
13
+ filename="unsloth.Q8_0.gguf"
14
+ )
15
+
16
+
17
+ def load_html(file_path):
18
+ with open(file_path, "r", encoding="utf-8") as file:
19
+ return file.read()
20
+
21
+ st.markdown(load_html("chatbot_ui.html"), unsafe_allow_html=True)
22
+ st.markdown('<div class="title">HR Chatbot</div>', unsafe_allow_html=True)
23
+ st.write("\n\n\n")
24
+
25
+
26
+ intents = {
27
+
28
+ "Employee Benefits & Policies": "Assist with salary, leave, and policies.",
29
+ "Employee Support & Self-Service": "Provide support for HR-related queries.",
30
+ "Recruitment & Onboarding": "Help with job applications and hiring processes."
31
+ }
32
+
33
+
34
+ intent_keywords = {
35
+
36
+ "Employee Benefits & Policies": ["leave", "insurance", "policy", "benefit", "salary", "payroll", "bonus"],
37
+ "Employee Support & Self-Service": ["complaint", "technical issue", "self-service", "support", "HR help"],
38
+ "Recruitment & Onboarding": ["hiring", "job", "apply", "interview", "onboarding", "new employee"]
39
+ }
40
+
41
+
42
+ def determine_intent(question):
43
+ question_lower = question.lower()
44
+ for intent, keywords in intent_keywords.items():
45
+ if any(keyword in question_lower for keyword in keywords):
46
+ return intent
47
+ return None
48
+
49
+
50
+ if "selected_intent" not in st.session_state:
51
+ st.session_state.selected_intent = list(intents.keys())[0]
52
+
53
+ cols = st.columns(len(intents))
54
+ for i, (intent, desc) in enumerate(intents.items()):
55
+ btn_label = f"βœ… **{intent}**" if st.session_state.selected_intent == intent else intent
56
+ if cols[i].button(btn_label, key=intent, help=desc):
57
+ st.session_state.selected_intent = intent
58
+ st.rerun()
59
+
60
+ if "messages" not in st.session_state:
61
+ st.session_state.messages = []
62
+
63
+
64
+ if st.session_state.messages:
65
+ st.markdown('<div class="chat-container">', unsafe_allow_html=True)
66
+ for msg in st.session_state.messages:
67
+ role_class = "user-msg" if msg["role"] == "user" else "bot-msg"
68
+ with st.chat_message(msg["role"]):
69
+ st.markdown(f'<div class="chat-box {role_class}">{msg["content"]}</div>', unsafe_allow_html=True)
70
+
71
+
72
+ if prompt := st.chat_input("Ask me anything related to HR..."):
73
+
74
+ st.session_state.messages.append({"role": "user", "content": prompt})
75
+
76
+ with st.chat_message("user"):
77
+ st.markdown(f'<div class="chat-box user-msg">πŸ‘€ {prompt}</div>', unsafe_allow_html=True)
78
+
79
+
80
+ correct_intent = determine_intent(prompt)
81
+
82
+ if correct_intent and correct_intent != st.session_state.selected_intent:
83
+
84
+ reply = f"πŸ”„ Redirecting... Your query belongs to '{correct_intent}'. Please select the correct category."
85
+ else:
86
+ with st.spinner("πŸ€” Thinking..."):
87
+ response = llm.create_chat_completion(
88
+ messages=[{"role": "user", "content": prompt}],
89
+ max_tokens=280
90
+ )
91
+ reply = response["choices"][0]["message"]["content"]
92
+
93
+
94
+ st.session_state.messages.append({"role": "assistant", "content": reply})
95
+
96
+ with st.chat_message("assistant"):
97
+ st.markdown(f'<div class="chat-box bot-msg">πŸ€– {reply}</div>', unsafe_allow_html=True)
98
+
99
+ if st.session_state.messages:
100
+ st.markdown('</div>', unsafe_allow_html=True)
chatbot_ui.html ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <style>
2
+ .title {
3
+ text-align: center;
4
+ font-size: 28px;
5
+ font-weight: bold;
6
+ margin-bottom: 10px;
7
+ }
8
+ .chat-container {
9
+ border: 2px solid #444;
10
+ padding: 15px;
11
+ border-radius: 10px;
12
+ background-color: #222;
13
+ }
14
+ .chat-box {
15
+ background-color: #222;
16
+ padding: 10px;
17
+ border-radius: 10px;
18
+ margin-bottom: 10px;
19
+ border: 1px solid #555;
20
+ }
21
+ .user-msg {
22
+ background-color: #1a1a1a;
23
+ padding: 10px;
24
+ border-radius: 10px;
25
+ color: white;
26
+ border: 1px solid #777;
27
+ }
28
+ .bot-msg {
29
+ background-color: #333;
30
+ padding: 10px;
31
+ border-radius: 10px;
32
+ color: white;
33
+ border: 1px solid #999;
34
+ }
35
+ .intent-buttons {
36
+ display: flex;
37
+ justify-content: center;
38
+ gap: 10px;
39
+ }
40
+ .selected-intent {
41
+ background-color: #4CAF50 !important; /* Green for selected button */
42
+ color: white !important;
43
+ }
44
+ </style>
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ streamlit
3
+ python-dotenv
4
+ llama-cpp-python