85 lines
2.1 KiB
Python
85 lines
2.1 KiB
Python
import streamlit as st
|
|
import requests
|
|
|
|
# Initialize session state for prompt history
|
|
if "history" not in st.session_state:
|
|
st.session_state.history = []
|
|
|
|
|
|
# Function to send POST request to a local server
|
|
def send_post_request(prompt):
|
|
url = "http://localhost:19194/" # Update this to your actual server URL
|
|
payload = prompt.title()
|
|
response = requests.post(url, json=payload)
|
|
json = response.json()
|
|
if "response" in json:
|
|
return json["response"]
|
|
else:
|
|
return json
|
|
|
|
|
|
# Custom CSS to fix the input box at the bottom of the page
|
|
st.markdown(
|
|
"""
|
|
<style>
|
|
.fixed-input-container {
|
|
position: fixed;
|
|
bottom: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
background-color: #f9f9f9;
|
|
padding: 10px;
|
|
box-shadow: 0px -2px 10px rgba(0, 0, 0, 0.1);
|
|
z-index: 999;
|
|
}
|
|
.input-container input {
|
|
width: 80%;
|
|
padding: 10px;
|
|
font-size: 16px;
|
|
border-radius: 5px;
|
|
border: 1px solid #ccc;
|
|
margin-right: 10px;
|
|
}
|
|
.input-container button {
|
|
padding: 10px 20px;
|
|
font-size: 16px;
|
|
border: none;
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
}
|
|
.input-container button:hover {
|
|
background-color: #45a049;
|
|
}
|
|
.prompt-history {
|
|
margin-bottom: 120px; /* Space to ensure prompt history doesn't overlap input box */
|
|
}
|
|
</style>
|
|
""",
|
|
unsafe_allow_html=True
|
|
)
|
|
|
|
st.title('Ask maargdarshak')
|
|
|
|
if 'messages' not in st.session_state:
|
|
st.session_state.messages = []
|
|
|
|
for message in st.session_state.messages:
|
|
st.chat_message(message['role']).markdown(message['content'])
|
|
|
|
prompt = st.chat_input("Ask your question here")
|
|
|
|
if prompt:
|
|
st.chat_message('user').markdown(prompt)
|
|
st.session_state.messages.append({'role': 'user', 'content': prompt})
|
|
|
|
response = send_post_request(prompt)
|
|
print(response)
|
|
st.chat_message('bot').markdown(response)
|
|
st.session_state.messages.append({'role': 'bot', 'content': response})
|
|
# st.session_state.history.append((prompt, response))
|
|
# st.experimental_rerun()
|
|
|
|
|