Spaces:
Paused
Paused
File size: 2,938 Bytes
2f68ed7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
import base64
import streamlit as st
# Set page configuration
st.set_page_config(
page_title="DLA",
page_icon=":robot:",
layout="centered",
initial_sidebar_state="collapsed",
)
# Custom CSS to change the background color and add a logo
st.markdown(
"""
<style>
.stApp {
background-color: black;
color: white;
}
.logo-container {
margin-bottom: 20px;
}
.logo {
width: 150px;
}
.chat-container {
border-radius: 10px;
padding: 5px;
margin-top: 20px;
width: 100%;
}
.qa-container {
border-top: 1px dashed silver;
border-bottom: 1px dashed silver;
padding: 10px;
margin-top: 20px;
width: 100%;
}
.message {
margin-bottom: 15px;
padding: 10px;
border-radius: 5px;
}
.user-message {
background-color: #373749;
color: silver;
}
.bot-message {
background-color: #333333;
color: silver;
}
</style>
""",
unsafe_allow_html=True,
)
def get_image_base64(image_path):
with open(image_path, "rb") as img_file:
return base64.b64encode(img_file.read()).decode()
image_base64 = get_image_base64("./DLA.png")
# Add logo at the top
st.markdown(
f"""
<div class="logo-container">
<div style = "text-align:left; border: width: 15%; float:left"><img src="data:image/png;base64,{image_base64}" alt="Logo" style="width:80px;"></div>
<div style = "color:#FFD700; text-shadow: 5px 5px #99ccff; font-family:Cursive; font-size:48px; font-weight:bold; text-align:center; width: 80%; float:left">DLA GPT</div>
</div>
""",
unsafe_allow_html=True,
)
# Chatbot interaction logic
if "messages" not in st.session_state:
st.session_state.messages = []
def get_bot_response(user_message):
# Simple bot response logic (you can replace this with a more complex chatbot model)
if "hello" in user_message.lower():
return "Hello! How can I help you today?"
else:
return "I'm here to assist you with any questions you have."
def display_history():
# Chat interface
st.markdown("<div class='chat-container' style = 'color: #9999b2; font-weight:bold; font-style: italic;'>Here is the answer", unsafe_allow_html=True)
for message in st.session_state.messages[:10]:
st.markdown(f"<div class = 'qa-container'><div class='message user-message'><b>You</b>: {message[0]}</div><div class='message bot-message'><b>Bot</b>: {message[1]}</div></div>", unsafe_allow_html=True)
st.markdown("</div>", unsafe_allow_html=True)
def main():
user_input = st.text_input(" ", "")
if user_input:
bot_response = get_bot_response(user_input)
message_pair = (user_input, bot_response)
st.session_state.messages.insert(0, message_pair)
display_history()
if __name__ == '__main__':
main()
|