Spaces:
Build error
Build error
Update app.py
Browse files8 unmodified lines91011121314151617181920212223247 unmodified lines32333435363738394041424344454647484950515253545556575859601 unmodified line6263646566676869707172737475767778798081828384852 unmodified lines8889909192939495969798991001011028 unmodified lineswarnings.filterwarnings("ignore")# Streamlit settingsst.set_page_config(page_title="πΏ ArchanaCare π§ββοΈ", page_icon="π§ββοΈ", layout="centered")st.markdown("<h1 style='text-align: center; color: #4B0082;'>Welcome to ArchanaCare πΏβ¨</h1>", unsafe_allow_html=True)st.markdown("<h3 style='color: #003366;'>How can I assist with your ailments or worries today? π§ͺπ«</h3>", unsafe_allow_html=True)# Adding vertical space without streamlit_extrasst.markdown("<br><br>", unsafe_allow_html=True)# Initialize session state for messages with an introductory messageif "sessionMessages" not in st.session_state:st.session_state["sessionMessages"] = [SystemMessage(content="You are a medieval magical healer known for your peculiar sarcasm.")]7 unmodified linesconvert_system_message_to_human=True)# Define a function to create chat bubblesdef chat_bubble(message, is_user=True):align = 'right' if is_user else 'left'color = '#ADD8E6' if is_user else '#E6E6FA'border_radius = '25px' if is_user else '25px'st.markdown(f"""<div style="text-align: {align}; padding: 10px;"><span style="display: inline-block; padding: 10px; background-color: {color}; color: black;border-radius: {border_radius}; max-width: 70%;">{message}</span></div>""", unsafe_allow_html=True)# Response functiondef load_answer(question):# Add user question to the message historyst.session_state.sessionMessages.append(HumanMessage(content=question))# Get AI's responseassistant_answer = llm.invoke(st.session_state.sessionMessages)# Append AI's answer to the session messagesif isinstance(assistant_answer, AIMessage):st.session_state.sessionMessages.append(assistant_answer)return assistant_answer.content1 unmodified linest.session_state.sessionMessages.append(AIMessage(content=assistant_answer))return assistant_answer# Capture user inputdef get_text():input_text = st.text_input("You: ", key="input", placeholder="Type your question here...")return str(input_text)# Main implementationuser_input = get_text()submit = st.button("π Get a Magical Answer π")if submit and user_input:# Display the user's questionchat_bubble(user_input, is_user=True)# Load the response and display it as a chat bubbleresponse = load_answer(user_input)chat_bubble(response, is_user=False)# Background styling and layout enhancementsst.markdown("""<style>.stApp {2 unmodified linesfont-family: Arial, sans-serif;}input[type="text"] {padding: 8px;border: 2px solid #4B0082;border-radius: 15px;outline: none;}button {background-color: #4B0082;color: white;border-radius: 15px;}</style>""", unsafe_allow_html=True)8 unmodified lines910111213141516171819202122237 unmodified lines3132333435363738394041424344454647484950515253541 unmodified line5657585960616263646566676869707172737475767778792 unmodified lines82838485868788899091929394959697988 unmodified lineswarnings.filterwarnings("ignore")# Streamlit settingsst.set_page_config(page_title="πΏ ArchanaCare π§ββοΈ", page_icon="π§ββοΈ", layout="wide")# Headerst.markdown("<h1 style='text-align: center; color: #4B0082;'>Welcome to ArchanaCare πΏβ¨</h1>", unsafe_allow_html=True)st.markdown("<h3 style='color: #003366;'>How can I assist with your ailments or worries today? π§ͺπ«</h3>", unsafe_allow_html=True)# Initialize session state for messagesif "sessionMessages" not in st.session_state:st.session_state.sessionMessages = [SystemMessage(content="You are a medieval magical healer known for your peculiar sarcasm.")]7 unmodified linesconvert_system_message_to_human=True)# Function to create chat bubblesdef chat_bubble(message, is_user=True):align = 'right' if is_user else 'left'color = '#E1F5FE' if is_user else '#FFEBEE'st.markdown(f"""<div style="text-align: {align}; padding: 10px;"><span style="display: inline-block; padding: 10px; background-color: {color}; color: black;border-radius: 15px; max-width: 70%; word-wrap: break-word;">{message}</span></div>""", unsafe_allow_html=True)# Function to load answer from the modeldef load_answer(question):st.session_state.sessionMessages.append(HumanMessage(content=question))assistant_answer = llm.invoke(st.session_state.sessionMessages)if isinstance(assistant_answer, AIMessage):st.session_state.sessionMessages.append(assistant_answer)return assistant_answer.content1 unmodified linest.session_state.sessionMessages.append(AIMessage(content=assistant_answer))return assistant_answer# Chat history displayfor message in st.session_state.sessionMessages:if isinstance(message, HumanMessage):chat_bubble(message.content, is_user=True)elif isinstance(message, AIMessage):chat_bubble(message.content, is_user=False)# Input areauser_input = st.text_input("You: ", key="input", placeholder="Type your question here...")# Button for submissionif st.button("π Get a Magical Answer π"):if user_input:chat_bubble(user_input, is_user=True) # Display user inputresponse = load_answer(user_input) # Get responsechat_bubble(response, is_user=False) # Display AI response# Background stylingst.markdown("""<style>.stApp {2 unmodified linesfont-family: Arial, sans-serif;}input[type="text"] {padding: 10px;border: 2px solid #4B0082;border-radius: 15px;outline: none;width: 100%;}button {background-color: #4B0082;color: white;border-radius: 15px;margin-top: 10px;}</style>""", unsafe_allow_html=True)
app.py+27-31