Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -91,69 +91,39 @@ def main():
|
|
| 91 |
initial_sidebar_state="expanded"
|
| 92 |
)
|
| 93 |
|
| 94 |
-
# Custom CSS for
|
| 95 |
st.markdown(
|
| 96 |
"""
|
| 97 |
<style>
|
| 98 |
-
body {
|
| 99 |
-
font-family: 'Arial', sans-serif;
|
| 100 |
-
background-color: #f4f6f9;
|
| 101 |
-
color: #333;
|
| 102 |
-
}
|
| 103 |
.main {
|
| 104 |
-
background-color: #
|
| 105 |
-
padding:
|
| 106 |
border-radius: 10px;
|
| 107 |
-
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 108 |
}
|
| 109 |
.sidebar .sidebar-content {
|
| 110 |
background-color: #2c3e50;
|
| 111 |
color: white;
|
| 112 |
-
padding: 20px;
|
| 113 |
-
border-radius: 10px;
|
| 114 |
}
|
| 115 |
.sidebar .sidebar-content .title {
|
| 116 |
font-size: 24px;
|
| 117 |
font-weight: bold;
|
| 118 |
-
margin-bottom: 20px;
|
| 119 |
}
|
| 120 |
.sidebar .sidebar-content .button {
|
| 121 |
background-color: #3498db;
|
| 122 |
border: none;
|
| 123 |
color: white;
|
| 124 |
-
padding:
|
| 125 |
text-align: center;
|
| 126 |
text-decoration: none;
|
| 127 |
display: inline-block;
|
| 128 |
font-size: 16px;
|
| 129 |
-
margin:
|
| 130 |
cursor: pointer;
|
| 131 |
-
border-radius:
|
| 132 |
-
transition: background-color 0.3s ease;
|
| 133 |
}
|
| 134 |
.sidebar .sidebar-content .button:hover {
|
| 135 |
background-color: #2980b9;
|
| 136 |
}
|
| 137 |
-
.chat-message {
|
| 138 |
-
display: flex;
|
| 139 |
-
align-items: center;
|
| 140 |
-
padding: 15px;
|
| 141 |
-
border-radius: 10px;
|
| 142 |
-
margin-bottom: 10px;
|
| 143 |
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
| 144 |
-
}
|
| 145 |
-
.chat-message img {
|
| 146 |
-
width: 40px;
|
| 147 |
-
height: 40px;
|
| 148 |
-
border-radius: 50%;
|
| 149 |
-
margin-right: 10px;
|
| 150 |
-
}
|
| 151 |
-
.user-message {
|
| 152 |
-
background-color: #d6eaf8;
|
| 153 |
-
}
|
| 154 |
-
.assistant-message {
|
| 155 |
-
background-color: #d5dbdb;
|
| 156 |
-
}
|
| 157 |
</style>
|
| 158 |
""",
|
| 159 |
unsafe_allow_html=True
|
|
@@ -189,25 +159,26 @@ def main():
|
|
| 189 |
|
| 190 |
# Display chat messages
|
| 191 |
for message in st.session_state.messages:
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
st.markdown(f'<div class="chat-message {css_class}"><img src="{icon}" alt="icon"><div>{message["content"]}</div></div>', unsafe_allow_html=True)
|
| 195 |
|
| 196 |
# Chat input
|
| 197 |
if prompt := st.chat_input():
|
| 198 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 199 |
-
st.
|
|
|
|
| 200 |
|
| 201 |
# Generate bot response
|
| 202 |
if st.session_state.messages[-1]["role"] != "assistant":
|
| 203 |
try:
|
| 204 |
-
with st.
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
| 211 |
except RuntimeError as e:
|
| 212 |
st.error(str(e))
|
| 213 |
|
|
|
|
| 91 |
initial_sidebar_state="expanded"
|
| 92 |
)
|
| 93 |
|
| 94 |
+
# Custom CSS for better design
|
| 95 |
st.markdown(
|
| 96 |
"""
|
| 97 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
.main {
|
| 99 |
+
background-color: #f0f2f6;
|
| 100 |
+
padding: 20px;
|
| 101 |
border-radius: 10px;
|
|
|
|
| 102 |
}
|
| 103 |
.sidebar .sidebar-content {
|
| 104 |
background-color: #2c3e50;
|
| 105 |
color: white;
|
|
|
|
|
|
|
| 106 |
}
|
| 107 |
.sidebar .sidebar-content .title {
|
| 108 |
font-size: 24px;
|
| 109 |
font-weight: bold;
|
|
|
|
| 110 |
}
|
| 111 |
.sidebar .sidebar-content .button {
|
| 112 |
background-color: #3498db;
|
| 113 |
border: none;
|
| 114 |
color: white;
|
| 115 |
+
padding: 10px;
|
| 116 |
text-align: center;
|
| 117 |
text-decoration: none;
|
| 118 |
display: inline-block;
|
| 119 |
font-size: 16px;
|
| 120 |
+
margin: 4px 2px;
|
| 121 |
cursor: pointer;
|
| 122 |
+
border-radius: 16px;
|
|
|
|
| 123 |
}
|
| 124 |
.sidebar .sidebar-content .button:hover {
|
| 125 |
background-color: #2980b9;
|
| 126 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
</style>
|
| 128 |
""",
|
| 129 |
unsafe_allow_html=True
|
|
|
|
| 159 |
|
| 160 |
# Display chat messages
|
| 161 |
for message in st.session_state.messages:
|
| 162 |
+
with st.chat_message(message["role"]):
|
| 163 |
+
st.write(message["content"])
|
|
|
|
| 164 |
|
| 165 |
# Chat input
|
| 166 |
if prompt := st.chat_input():
|
| 167 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 168 |
+
with st.chat_message("user"):
|
| 169 |
+
st.write(prompt)
|
| 170 |
|
| 171 |
# Generate bot response
|
| 172 |
if st.session_state.messages[-1]["role"] != "assistant":
|
| 173 |
try:
|
| 174 |
+
with st.chat_message("assistant"):
|
| 175 |
+
with st.spinner("Thinking..."):
|
| 176 |
+
response = user_input(prompt)
|
| 177 |
+
if response:
|
| 178 |
+
full_response = ''.join(response['output_text'])
|
| 179 |
+
st.write(full_response)
|
| 180 |
+
message = {"role": "assistant", "content": full_response}
|
| 181 |
+
st.session_state.messages.append(message)
|
| 182 |
except RuntimeError as e:
|
| 183 |
st.error(str(e))
|
| 184 |
|