Spaces:
Sleeping
Sleeping
Upload base-app.py
Browse files- base-app.py +36 -0
base-app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# App title
|
| 4 |
+
st.set_page_config(page_title="Herbal-Expert")
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# Store LLM generated responses
|
| 8 |
+
if "messages" not in st.session_state.keys():
|
| 9 |
+
st.session_state.messages = [{"role": "assistant", "content": "How may I help you?"}]
|
| 10 |
+
|
| 11 |
+
# Display chat messages
|
| 12 |
+
for message in st.session_state.messages:
|
| 13 |
+
with st.chat_message(message["role"]):
|
| 14 |
+
st.write(message["content"])
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
# Function for generating LLM response
|
| 18 |
+
def generate_response(prompt_input):
|
| 19 |
+
print("someone's here")
|
| 20 |
+
return "hello world"
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# User-provided prompt
|
| 24 |
+
if prompt := st.chat_input():
|
| 25 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 26 |
+
with st.chat_message("user"):
|
| 27 |
+
st.write(prompt)
|
| 28 |
+
|
| 29 |
+
# Generate a new response if last message is not from assistant
|
| 30 |
+
if st.session_state.messages[-1]["role"] != "assistant":
|
| 31 |
+
with st.chat_message("assistant"):
|
| 32 |
+
with st.spinner("Thinking..."):
|
| 33 |
+
response = generate_response(prompt)
|
| 34 |
+
st.write(response)
|
| 35 |
+
message = {"role": "assistant", "content": response}
|
| 36 |
+
st.session_state.messages.append(message)
|