ghengx commited on
Commit
b8c950d
·
1 Parent(s): 7e7660f
Files changed (2) hide show
  1. app.py +57 -0
  2. requirements.txt +62 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ import time
4
+ # from dotenv import load_dotenv
5
+ from chatbot_function.chatbot import answer
6
+ from huggingface_hub import Repository
7
+ from huggingface_hub import login
8
+
9
+ # load_dotenv()
10
+
11
+ login(token = os.environ['HF_TOKEN'])
12
+
13
+ repo = Repository(
14
+ local_dir="chatbot_function",
15
+ repo_type="dataset",
16
+ clone_from=os.environ['DATASET'],
17
+ token=True
18
+ )
19
+ repo.git_pull()
20
+
21
+
22
+ # Streamed response emulator
23
+ def response_generator(query):
24
+ ans = answer(query)
25
+
26
+ for word in ans.split(' '):
27
+ yield word + " "
28
+ time.sleep(0.05)
29
+
30
+ st.title("Nirvana Chatbot")
31
+
32
+ if 'conversation_id' not in st.session_state:
33
+ st.session_state['conversation_id'] = ''
34
+
35
+ # Initialize chat history
36
+ if "messages" not in st.session_state:
37
+ st.session_state.messages = []
38
+
39
+ # Display chat messages from history on app rerun
40
+ for message in st.session_state.messages:
41
+ with st.chat_message(message["role"]):
42
+ st.markdown(message["content"])
43
+
44
+ # Accept user input
45
+ if prompt := st.chat_input("What is up?"):
46
+ # Add user message to chat history
47
+ st.session_state.messages.append({"role": "user", "content": prompt})
48
+ # Display user message in chat message container
49
+ with st.chat_message("user"):
50
+ st.markdown(prompt)
51
+
52
+ # Display assistant response in chat message container
53
+ with st.chat_message("assistant"):
54
+ response = st.write_stream(response_generator(prompt))
55
+
56
+ # Add assistant response to chat history
57
+ st.session_state.messages.append({"role": "assistant", "content": response})
requirements.txt ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==5.5.0
2
+ annotated-types==0.7.0
3
+ anyio==4.7.0
4
+ attrs==24.3.0
5
+ blinker==1.9.0
6
+ cachetools==5.5.0
7
+ certifi==2024.12.14
8
+ charset-normalizer==3.4.1
9
+ click==8.1.8
10
+ distro==1.9.0
11
+ filelock==3.16.1
12
+ fsspec==2024.12.0
13
+ gitdb==4.0.11
14
+ GitPython==3.1.43
15
+ h11==0.14.0
16
+ httpcore==1.0.7
17
+ httpx==0.28.1
18
+ huggingface-hub==0.27.0
19
+ idna==3.10
20
+ Jinja2==3.1.5
21
+ jiter==0.8.2
22
+ joblib==1.4.2
23
+ jsonschema==4.23.0
24
+ jsonschema-specifications==2024.10.1
25
+ markdown-it-py==3.0.0
26
+ MarkupSafe==3.0.2
27
+ mdurl==0.1.2
28
+ narwhals==1.19.1
29
+ numpy==2.2.1
30
+ openai==1.58.1
31
+ packaging==24.2
32
+ pandas==2.2.3
33
+ pillow==11.0.0
34
+ protobuf==5.29.2
35
+ pyarrow==18.1.0
36
+ pydantic==2.10.4
37
+ pydantic_core==2.27.2
38
+ pydeck==0.9.1
39
+ Pygments==2.18.0
40
+ python-dateutil==2.9.0.post0
41
+ python-dotenv==1.0.1
42
+ pytz==2024.2
43
+ PyYAML==6.0.2
44
+ referencing==0.35.1
45
+ requests==2.32.3
46
+ rich==13.9.4
47
+ rpds-py==0.22.3
48
+ scikit-learn==1.6.0
49
+ scipy==1.14.1
50
+ six==1.17.0
51
+ smmap==5.0.1
52
+ sniffio==1.3.1
53
+ streamlit==1.41.1
54
+ tabulate==0.9.0
55
+ tenacity==9.0.0
56
+ threadpoolctl==3.5.0
57
+ toml==0.10.2
58
+ tornado==6.4.2
59
+ tqdm==4.67.1
60
+ typing_extensions==4.12.2
61
+ tzdata==2024.2
62
+ urllib3==2.3.0