Spaces:
Sleeping
Sleeping
ghengx
commited on
Commit
·
b5cccbd
1
Parent(s):
a93d518
init
Browse files- app.py +55 -0
- requirements.txt +45 -0
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
import time
|
4 |
+
from huggingface_hub import Repository
|
5 |
+
from huggingface_hub import login
|
6 |
+
|
7 |
+
login(token = os.environ['HF_TOKEN'])
|
8 |
+
|
9 |
+
repo = Repository(
|
10 |
+
local_dir="chatbot_function",
|
11 |
+
repo_type="dataset",
|
12 |
+
clone_from=os.environ['DATASET'],
|
13 |
+
token=True
|
14 |
+
)
|
15 |
+
repo.git_pull()
|
16 |
+
|
17 |
+
from chatbot_function.agent import ask
|
18 |
+
|
19 |
+
|
20 |
+
# Streamed response emulator
|
21 |
+
def response_generator(query):
|
22 |
+
ans = ask(query)
|
23 |
+
|
24 |
+
for word in ans.split(' '):
|
25 |
+
yield word + " "
|
26 |
+
time.sleep(0.05)
|
27 |
+
|
28 |
+
st.title("HR Chatbot")
|
29 |
+
|
30 |
+
if 'conversation_id' not in st.session_state:
|
31 |
+
st.session_state['conversation_id'] = ''
|
32 |
+
|
33 |
+
# Initialize chat history
|
34 |
+
if "messages" not in st.session_state:
|
35 |
+
st.session_state.messages = []
|
36 |
+
|
37 |
+
# Display chat messages from history on app rerun
|
38 |
+
for message in st.session_state.messages:
|
39 |
+
with st.chat_message(message["role"]):
|
40 |
+
st.markdown(message["content"])
|
41 |
+
|
42 |
+
# Accept user input
|
43 |
+
if prompt := st.chat_input("What is up?"):
|
44 |
+
# Add user message to chat history
|
45 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
46 |
+
# Display user message in chat message container
|
47 |
+
with st.chat_message("user"):
|
48 |
+
st.markdown(prompt)
|
49 |
+
|
50 |
+
# Display assistant response in chat message container
|
51 |
+
with st.chat_message("assistant"):
|
52 |
+
response = st.write_stream(response_generator(prompt))
|
53 |
+
|
54 |
+
# Add assistant response to chat history
|
55 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
requirements.txt
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
altair==5.5.0
|
2 |
+
attrs==25.1.0
|
3 |
+
blinker==1.9.0
|
4 |
+
cachetools==5.5.1
|
5 |
+
certifi==2025.1.31
|
6 |
+
charset-normalizer==3.4.1
|
7 |
+
click==8.1.8
|
8 |
+
filelock==3.17.0
|
9 |
+
fsspec==2025.2.0
|
10 |
+
gitdb==4.0.12
|
11 |
+
GitPython==3.1.44
|
12 |
+
huggingface-hub==0.28.1
|
13 |
+
idna==3.10
|
14 |
+
Jinja2==3.1.5
|
15 |
+
jsonschema==4.23.0
|
16 |
+
jsonschema-specifications==2024.10.1
|
17 |
+
markdown-it-py==3.0.0
|
18 |
+
MarkupSafe==3.0.2
|
19 |
+
mdurl==0.1.2
|
20 |
+
narwhals==1.24.2
|
21 |
+
numpy==2.2.2
|
22 |
+
packaging==24.2
|
23 |
+
pandas==2.2.3
|
24 |
+
pillow==11.1.0
|
25 |
+
protobuf==5.29.3
|
26 |
+
pyarrow==19.0.0
|
27 |
+
pydeck==0.9.1
|
28 |
+
Pygments==2.19.1
|
29 |
+
python-dateutil==2.9.0.post0
|
30 |
+
pytz==2025.1
|
31 |
+
PyYAML==6.0.2
|
32 |
+
referencing==0.36.2
|
33 |
+
requests==2.32.3
|
34 |
+
rich==13.9.4
|
35 |
+
rpds-py==0.22.3
|
36 |
+
six==1.17.0
|
37 |
+
smmap==5.0.2
|
38 |
+
streamlit==1.41.1
|
39 |
+
tenacity==9.0.0
|
40 |
+
toml==0.10.2
|
41 |
+
tornado==6.4.2
|
42 |
+
tqdm==4.67.1
|
43 |
+
typing_extensions==4.12.2
|
44 |
+
tzdata==2025.1
|
45 |
+
urllib3==2.3.0
|