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