Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +43 -0
- dataset_loader.py +18 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
from dataset_loader import load_dataset
|
5 |
+
|
6 |
+
if not os.path.isdir("jlc_chatbot_data"):
|
7 |
+
load_dataset()
|
8 |
+
|
9 |
+
from jlc_chatbot_data.utils import run_conversation
|
10 |
+
|
11 |
+
|
12 |
+
import streamlit as st
|
13 |
+
import traceback
|
14 |
+
|
15 |
+
st.set_page_config(page_title="Facility Management Chatbot", page_icon=":robot:")
|
16 |
+
|
17 |
+
|
18 |
+
if "messages" not in st.session_state:
|
19 |
+
st.session_state.messages = [
|
20 |
+
{"role": "assistant", "content": "How may I help you?"}
|
21 |
+
]
|
22 |
+
|
23 |
+
for message in st.session_state.messages:
|
24 |
+
with st.chat_message(message["role"]):
|
25 |
+
st.write(message["content"])
|
26 |
+
|
27 |
+
if prompt := st.chat_input():
|
28 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
29 |
+
with st.chat_message("user"):
|
30 |
+
st.write(prompt)
|
31 |
+
|
32 |
+
if st.session_state.messages[-1]["role"] != "assistant":
|
33 |
+
try:
|
34 |
+
with st.chat_message("assistant"):
|
35 |
+
with st.spinner("Thinking..."):
|
36 |
+
answer = run_conversation(st.session_state.messages, prompt)
|
37 |
+
st.write(answer.replace("\n", " \n"))
|
38 |
+
|
39 |
+
message = {"role": "assistant", "content": answer}
|
40 |
+
st.session_state.messages.append(message)
|
41 |
+
except:
|
42 |
+
st.error("An error occurred. Please try again.")
|
43 |
+
traceback.print_exc()
|
dataset_loader.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import Repository
|
2 |
+
from huggingface_hub import login
|
3 |
+
import os
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
|
6 |
+
load_dotenv()
|
7 |
+
|
8 |
+
|
9 |
+
def load_dataset():
|
10 |
+
login(token=os.getenv("HUB_TOKEN"))
|
11 |
+
|
12 |
+
repo = Repository(
|
13 |
+
local_dir="jlc_chatbot_data",
|
14 |
+
repo_type="dataset",
|
15 |
+
clone_from="cjzhi98/facility-management-chatbot",
|
16 |
+
token=True,
|
17 |
+
)
|
18 |
+
repo.git_pull()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
requests
|
2 |
+
python-dotenv
|
3 |
+
huggingface_hub
|
4 |
+
streamlit
|
5 |
+
openai
|