Spaces:
Sleeping
Sleeping
testing chat interface
Browse files
app.py
CHANGED
@@ -1,4 +1,46 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from huggingface_hub import hf_hub_download
|
3 |
+
from llama_cpp import Llama
|
4 |
|
5 |
+
hf_hub_download(repo_id="LLukas22/gpt4all-lora-quantized-ggjt", filename="ggjt-model.bin", local_dir=".")
|
6 |
+
llm = Llama(model_path="./ggjt-model.bin")
|
7 |
+
|
8 |
+
ins = '''### Instruction:
|
9 |
+
{}
|
10 |
+
### Response:
|
11 |
+
'''
|
12 |
+
|
13 |
+
fixed_instruction = "You are a healthcare bot designed to give advice for the prevention and treatment of various illnesses."
|
14 |
+
|
15 |
+
def respond(message):
|
16 |
+
full_instruction = fixed_instruction + " " + message
|
17 |
+
formatted_instruction = ins.format(full_instruction)
|
18 |
+
bot_message = llm(formatted_instruction, stop=['### Instruction:', '### End'])
|
19 |
+
bot_message = bot_message['choices'][0]['text']
|
20 |
+
return bot_message
|
21 |
+
|
22 |
+
st.title("Healthcare Bot")
|
23 |
+
|
24 |
+
# Initialize chat history
|
25 |
+
if "messages" not in st.session_state:
|
26 |
+
st.session_state.messages = []
|
27 |
+
|
28 |
+
# Display chat messages from history on app rerun
|
29 |
+
for message in st.session_state.messages:
|
30 |
+
with st.chat_message(message["role"]):
|
31 |
+
st.markdown(message["content"])
|
32 |
+
|
33 |
+
# React to user input
|
34 |
+
if prompt := st.chat_input("What is your question?"):
|
35 |
+
# Display user message in chat message container
|
36 |
+
st.chat_message("user").markdown(prompt)
|
37 |
+
# Add user message to chat history
|
38 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
39 |
+
|
40 |
+
response = respond(prompt)
|
41 |
+
# Display assistant response in chat message container
|
42 |
+
with st.chat_message("assistant"):
|
43 |
+
st.markdown(response)
|
44 |
+
# Add assistant response to chat history
|
45 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
46 |
+
)
|