Spaces:
Runtime error
Runtime error
import streamlit as st | |
import time | |
import main | |
# Initialize conversation history | |
if 'conversation' not in st.session_state: | |
st.session_state['conversation'] = [] | |
# Function to display conversation history | |
def display_conversation(): | |
for entry in st.session_state['conversation']: | |
if entry['type'] == 'bot': | |
st.markdown(f"<div style='background-color:#005691; padding:10px; border-radius:10px; margin:10px 0; color:white;'>{entry['message']}</div>", unsafe_allow_html=True) | |
else: | |
st.markdown(f"<div style='background-color:#f1f1f1; padding:10px; border-radius:10px; margin:10px 0;color:black;'>{entry['message']}</div>", unsafe_allow_html=True) | |
# Function to simulate chatbot response | |
def get_bot_response(user_input): | |
# Simulated bot response | |
response = main.ask_llms(user_input) | |
bot_response = f"Echo: {response}" | |
return bot_response | |
# Streamlit UI components | |
st.title("Professional Chatbot Interface") | |
# Display conversation | |
st.markdown("### Conversation") | |
display_conversation() | |
# User input | |
user_input = st.text_input("You", "") | |
# Button for user to submit the input | |
if st.button("Send"): | |
if user_input: | |
# Save user's message | |
st.session_state['conversation'].append({"type": "user", "message": user_input}) | |
# Get bot response and save it | |
bot_message = get_bot_response(user_input) | |
time.sleep(1) # Simulate delay | |
st.session_state['conversation'].append({"type": "bot", "message": bot_message}) | |
# Refresh the page after sending the message | |
st.rerun() | |
# Design Enhancements | |
# Custom CSS to style the input box | |
# Custom CSS to style the input box | |
st.markdown(""" | |
<style> | |
.stTextInput > div > input { | |
background-color: #1e1e1e !important; /* Darker background for better contrast */ | |
color: white !important; /* Ensure text is white */ | |
padding: 10px; | |
border-radius: 10px; | |
} | |
.css-1e5imcs {padding-top: 0rem;} /* Reduces top padding */ | |
</style> | |
""", unsafe_allow_html=True) | |