Spaces:
Sleeping
Sleeping
File size: 3,513 Bytes
2d828c9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
import streamlit as st
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
os.environ['TOKENIZERS_PARALLELISM'] = 'false'
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
import warnings
import logging
# Suppress all warnings
warnings.filterwarnings('ignore')
logging.getLogger().setLevel(logging.ERROR)
from osho_qa_service import get_answer_from_osho
# Set page config
st.set_page_config(
page_title="Ask Osho",
page_icon="π§ββοΈ",
layout="centered",
initial_sidebar_state="collapsed"
)
# Title and description
st.title("π§ββοΈ Ask Osho")
st.markdown("""
This application allows you to ask questions and receive answers from Osho's wisdom.
Choose from example questions or ask your own question.
""")
# Example questions
example_questions = [
"What is the relationship between breath and consciousness?",
"How can meditation help in daily life?",
"What is the difference between mind and consciousness?",
"What is the nature of love?",
"How can one find inner peace?"
]
# Initialize session state for question if not exists
if 'question' not in st.session_state:
st.session_state.question = ""
# Create columns for example questions
st.subheader("Example Questions")
cols = st.columns(3)
# Function to update question
def set_question(q):
st.session_state.question = q
# Create buttons for example questions
for i, question in enumerate(example_questions):
col_idx = i % 3
if cols[col_idx].button(f"Q{i+1}: {question[:30]}...", key=f"q{i}",
help=question): # Show full question on hover
set_question(question)
# Or ask your own question
st.subheader("Or Ask Your Own Question")
question = st.text_input("Type your question here:",
value=st.session_state.question,
key="question_input",
on_change=lambda: set_question(st.session_state.question_input))
# Answer button
if st.button("Please Answer Osho", type="primary", key="answer_button"):
if question:
with st.spinner("Seeking wisdom in Osho's teachings..."):
try:
# Get answer using the service
response = get_answer_from_osho(question)
# Display the answer in a nice box
st.markdown("---")
st.subheader("Osho's Answer")
# Main answer
main_passage = response['answer_passages'][0]
st.info(f"**From the book**: _{main_passage['book']}_")
st.markdown(main_passage['text'])
# Other references
other_books = [p['book'] for p in response['answer_passages'][1:]]
if other_books:
st.markdown("---")
st.success("**You can also explore these books:**")
for book in other_books:
st.markdown(f"- {book}")
except Exception as e:
st.error("Sorry, I encountered an error while processing your question. Please try again.")
st.error(f"Error details: {str(e)}")
else:
st.warning("Please enter a question or select an example question.")
# Add some styling
st.markdown("""
<style>
.stButton button {
width: 100%;
}
.stButton>button:first-child {
margin-top: 20px;
}
.stMarkdown {
text-align: justify;
}
</style>
""", unsafe_allow_html=True)
|