Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -95,54 +95,57 @@ def main():
|
|
| 95 |
st.markdown(
|
| 96 |
"""
|
| 97 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
.main {
|
| 99 |
-
background-color: #
|
| 100 |
-
padding:
|
| 101 |
border-radius: 10px;
|
| 102 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
| 103 |
}
|
| 104 |
.sidebar .sidebar-content {
|
| 105 |
-
background-color: #
|
| 106 |
-
color:
|
| 107 |
padding: 20px;
|
| 108 |
border-radius: 10px;
|
| 109 |
}
|
| 110 |
.sidebar .sidebar-content .title {
|
| 111 |
font-size: 24px;
|
| 112 |
font-weight: bold;
|
| 113 |
-
margin-bottom:
|
| 114 |
}
|
| 115 |
.sidebar .sidebar-content .button {
|
| 116 |
background-color: #3498db;
|
| 117 |
border: none;
|
| 118 |
color: white;
|
| 119 |
-
padding:
|
| 120 |
text-align: center;
|
| 121 |
text-decoration: none;
|
| 122 |
display: inline-block;
|
| 123 |
font-size: 16px;
|
| 124 |
-
margin:
|
| 125 |
cursor: pointer;
|
| 126 |
-
border-radius:
|
|
|
|
| 127 |
}
|
| 128 |
.sidebar .sidebar-content .button:hover {
|
| 129 |
background-color: #2980b9;
|
| 130 |
}
|
| 131 |
-
.sidebar .sidebar-content .file-uploader {
|
| 132 |
-
margin-bottom: 20px;
|
| 133 |
-
}
|
| 134 |
.chat-message {
|
| 135 |
-
background-color: #
|
| 136 |
padding: 15px;
|
| 137 |
border-radius: 10px;
|
| 138 |
margin-bottom: 10px;
|
| 139 |
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
| 140 |
}
|
| 141 |
.user-message {
|
| 142 |
-
background-color: #
|
| 143 |
}
|
| 144 |
.assistant-message {
|
| 145 |
-
background-color: #
|
| 146 |
}
|
| 147 |
</style>
|
| 148 |
""",
|
|
@@ -153,8 +156,8 @@ def main():
|
|
| 153 |
with st.sidebar:
|
| 154 |
st.title("Menu")
|
| 155 |
pdf_docs = st.file_uploader(
|
| 156 |
-
"Upload your PDF files", accept_multiple_files=True
|
| 157 |
-
if st.button("Submit & Process", key="submit_button"
|
| 158 |
if pdf_docs:
|
| 159 |
try:
|
| 160 |
with st.spinner("Processing..."):
|
|
@@ -170,7 +173,7 @@ def main():
|
|
| 170 |
# Main content area for displaying chat messages
|
| 171 |
st.title("Gemini PDF Chatbot")
|
| 172 |
st.write("Welcome to the Gemini PDF Chatbot! Upload your PDFs and ask questions.")
|
| 173 |
-
st.sidebar.button('Clear Chat History', on_click=clear_chat_history
|
| 174 |
|
| 175 |
# Initialize chat history
|
| 176 |
if "messages" not in st.session_state:
|
|
@@ -180,29 +183,25 @@ def main():
|
|
| 180 |
# Display chat messages
|
| 181 |
for message in st.session_state.messages:
|
| 182 |
css_class = "user-message" if message["role"] == "user" else "assistant-message"
|
| 183 |
-
|
| 184 |
-
st.write(message["content"])
|
| 185 |
|
| 186 |
# Chat input
|
| 187 |
if prompt := st.chat_input():
|
| 188 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 189 |
-
|
| 190 |
-
st.write(prompt)
|
| 191 |
|
| 192 |
# Generate bot response
|
| 193 |
if st.session_state.messages[-1]["role"] != "assistant":
|
| 194 |
try:
|
| 195 |
-
with st.
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
st.session_state.messages.append(message)
|
| 203 |
except RuntimeError as e:
|
| 204 |
st.error(str(e))
|
| 205 |
|
| 206 |
if __name__ == "__main__":
|
| 207 |
main()
|
| 208 |
-
|
|
|
|
| 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: #fff;
|
| 105 |
+
padding: 30px;
|
| 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: 12px 20px;
|
| 125 |
text-align: center;
|
| 126 |
text-decoration: none;
|
| 127 |
display: inline-block;
|
| 128 |
font-size: 16px;
|
| 129 |
+
margin: 8px 0;
|
| 130 |
cursor: pointer;
|
| 131 |
+
border-radius: 8px;
|
| 132 |
+
transition: background-color 0.3s ease;
|
| 133 |
}
|
| 134 |
.sidebar .sidebar-content .button:hover {
|
| 135 |
background-color: #2980b9;
|
| 136 |
}
|
|
|
|
|
|
|
|
|
|
| 137 |
.chat-message {
|
| 138 |
+
background-color: #ecf0f1;
|
| 139 |
padding: 15px;
|
| 140 |
border-radius: 10px;
|
| 141 |
margin-bottom: 10px;
|
| 142 |
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
| 143 |
}
|
| 144 |
.user-message {
|
| 145 |
+
background-color: #d6eaf8;
|
| 146 |
}
|
| 147 |
.assistant-message {
|
| 148 |
+
background-color: #d5dbdb;
|
| 149 |
}
|
| 150 |
</style>
|
| 151 |
""",
|
|
|
|
| 156 |
with st.sidebar:
|
| 157 |
st.title("Menu")
|
| 158 |
pdf_docs = st.file_uploader(
|
| 159 |
+
"Upload your PDF files", accept_multiple_files=True)
|
| 160 |
+
if st.button("Submit & Process", key="submit_button"):
|
| 161 |
if pdf_docs:
|
| 162 |
try:
|
| 163 |
with st.spinner("Processing..."):
|
|
|
|
| 173 |
# Main content area for displaying chat messages
|
| 174 |
st.title("Gemini PDF Chatbot")
|
| 175 |
st.write("Welcome to the Gemini PDF Chatbot! Upload your PDFs and ask questions.")
|
| 176 |
+
st.sidebar.button('Clear Chat History', on_click=clear_chat_history)
|
| 177 |
|
| 178 |
# Initialize chat history
|
| 179 |
if "messages" not in st.session_state:
|
|
|
|
| 183 |
# Display chat messages
|
| 184 |
for message in st.session_state.messages:
|
| 185 |
css_class = "user-message" if message["role"] == "user" else "assistant-message"
|
| 186 |
+
st.markdown(f'<div class="chat-message {css_class}">{message["content"]}</div>', unsafe_allow_html=True)
|
|
|
|
| 187 |
|
| 188 |
# Chat input
|
| 189 |
if prompt := st.chat_input():
|
| 190 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 191 |
+
st.markdown(f'<div class="chat-message user-message">{prompt}</div>', unsafe_allow_html=True)
|
|
|
|
| 192 |
|
| 193 |
# Generate bot response
|
| 194 |
if st.session_state.messages[-1]["role"] != "assistant":
|
| 195 |
try:
|
| 196 |
+
with st.spinner("Thinking..."):
|
| 197 |
+
response = user_input(prompt)
|
| 198 |
+
if response:
|
| 199 |
+
full_response = ''.join(response['output_text'])
|
| 200 |
+
st.markdown(f'<div class="chat-message assistant-message">{full_response}</div>', unsafe_allow_html=True)
|
| 201 |
+
message = {"role": "assistant", "content": full_response}
|
| 202 |
+
st.session_state.messages.append(message)
|
|
|
|
| 203 |
except RuntimeError as e:
|
| 204 |
st.error(str(e))
|
| 205 |
|
| 206 |
if __name__ == "__main__":
|
| 207 |
main()
|
|
|