Spaces:
Runtime error
Runtime error
nishantgaurav23
commited on
Commit
β’
9b8a800
1
Parent(s):
d715357
Update app.py
Browse files
app.py
CHANGED
@@ -499,6 +499,166 @@ def initialize_rag_pipeline():
|
|
499 |
# logging.error(f"Application error: {str(e)}")
|
500 |
# st.error("An unexpected error occurred. Please check the logs and try again.")
|
501 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
502 |
def main():
|
503 |
try:
|
504 |
# Environment check
|
@@ -575,18 +735,24 @@ def main():
|
|
575 |
</style>
|
576 |
""", unsafe_allow_html=True)
|
577 |
|
578 |
-
# Header section
|
579 |
-
st.markdown("<h1 class='main-title'>π The Sport Chatbot</h1>", unsafe_allow_html=True)
|
580 |
-
st.markdown("<h3 class='sub-title'>Using ESPN API</h3>", unsafe_allow_html=True)
|
581 |
st.markdown("""
|
582 |
<p class='description'>
|
583 |
Hey there! π I can help you with information on Ice Hockey, Baseball, American Football, Soccer, and Basketball.
|
584 |
With access to the ESPN API, I'm up to date with the latest details for these sports up until October 2024.
|
585 |
</p>
|
|
|
|
|
|
|
586 |
<p class='description'>
|
587 |
Got any general questions? Feel free to askβI'll do my best to provide answers based on the information I've been trained on!
|
588 |
</p>
|
589 |
-
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
590 |
|
591 |
# Initialize the pipeline with better error handling
|
592 |
if 'rag' not in st.session_state:
|
@@ -596,7 +762,7 @@ def main():
|
|
596 |
logging.info("Pipeline initialized successfully")
|
597 |
except Exception as e:
|
598 |
logging.error(f"Pipeline initialization error: {str(e)}")
|
599 |
-
st.error("Failed to initialize the system. Please check the logs.")
|
600 |
st.stop()
|
601 |
return
|
602 |
|
@@ -604,42 +770,54 @@ def main():
|
|
604 |
col1, col2, col3 = st.columns([1, 6, 1])
|
605 |
|
606 |
with col2:
|
607 |
-
# Query input
|
608 |
-
query = st.text_input(
|
|
|
|
|
|
|
609 |
|
610 |
-
|
|
|
611 |
if query:
|
612 |
response_placeholder = st.empty()
|
613 |
try:
|
614 |
# Log query processing start
|
615 |
logging.info(f"Processing query: {query}")
|
616 |
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
|
|
|
|
622 |
except Exception as e:
|
623 |
# Log error details
|
624 |
logging.error(f"Query processing error: {str(e)}")
|
625 |
logging.error("Full error details: ", exc_info=True)
|
626 |
-
response_placeholder.warning(
|
|
|
|
|
|
|
627 |
else:
|
628 |
-
st.warning("Please enter a question!")
|
629 |
|
630 |
-
# Footer
|
631 |
-
st.markdown("<br><br>", unsafe_allow_html=True)
|
632 |
-
st.markdown("---")
|
633 |
st.markdown("""
|
634 |
<p style='text-align: center; color: #666666; padding: 1rem 0;'>
|
635 |
Powered by ESPN Data & Mistral AI π
|
636 |
</p>
|
637 |
-
""", unsafe_allow_html=True)
|
638 |
|
639 |
except Exception as e:
|
640 |
logging.error(f"Application error: {str(e)}")
|
641 |
logging.error("Full error details: ", exc_info=True)
|
642 |
-
st.error(
|
|
|
|
|
|
|
643 |
|
644 |
if __name__ == "__main__":
|
645 |
# Configure logging
|
@@ -653,7 +831,7 @@ if __name__ == "__main__":
|
|
653 |
except Exception as e:
|
654 |
logging.error(f"Fatal error: {str(e)}")
|
655 |
logging.error("Full error details: ", exc_info=True)
|
656 |
-
st.error(
|
657 |
-
|
658 |
-
|
659 |
-
|
|
|
499 |
# logging.error(f"Application error: {str(e)}")
|
500 |
# st.error("An unexpected error occurred. Please check the logs and try again.")
|
501 |
|
502 |
+
# def main():
|
503 |
+
# try:
|
504 |
+
# # Environment check
|
505 |
+
# if not check_environment():
|
506 |
+
# return
|
507 |
+
|
508 |
+
# # Improved CSS styling
|
509 |
+
# st.markdown("""
|
510 |
+
# <style>
|
511 |
+
# /* Container styling */
|
512 |
+
# .block-container {
|
513 |
+
# padding-top: 2rem;
|
514 |
+
# padding-bottom: 2rem;
|
515 |
+
# }
|
516 |
+
|
517 |
+
# /* Text input styling */
|
518 |
+
# .stTextInput > div > div > input {
|
519 |
+
# width: 100%;
|
520 |
+
# }
|
521 |
+
|
522 |
+
# /* Button styling */
|
523 |
+
# .stButton > button {
|
524 |
+
# width: 200px;
|
525 |
+
# margin: 0 auto;
|
526 |
+
# display: block;
|
527 |
+
# background-color: #FF4B4B;
|
528 |
+
# color: white;
|
529 |
+
# border-radius: 5px;
|
530 |
+
# padding: 0.5rem 1rem;
|
531 |
+
# }
|
532 |
+
|
533 |
+
# /* Title styling */
|
534 |
+
# .main-title {
|
535 |
+
# text-align: center;
|
536 |
+
# padding: 1rem 0;
|
537 |
+
# font-size: 3rem;
|
538 |
+
# color: #1F1F1F;
|
539 |
+
# }
|
540 |
+
|
541 |
+
# .sub-title {
|
542 |
+
# text-align: center;
|
543 |
+
# padding: 0.5rem 0;
|
544 |
+
# font-size: 1.5rem;
|
545 |
+
# color: #4F4F4F;
|
546 |
+
# }
|
547 |
+
|
548 |
+
# /* Description styling */
|
549 |
+
# .description {
|
550 |
+
# text-align: center;
|
551 |
+
# color: #666666;
|
552 |
+
# padding: 0.5rem 0;
|
553 |
+
# font-size: 1.1rem;
|
554 |
+
# line-height: 1.6;
|
555 |
+
# margin-bottom: 1rem;
|
556 |
+
# }
|
557 |
+
|
558 |
+
# /* Answer container styling */
|
559 |
+
# .stMarkdown {
|
560 |
+
# max-width: 100%;
|
561 |
+
# }
|
562 |
+
|
563 |
+
# /* Streamlit default overrides */
|
564 |
+
# .st-emotion-cache-16idsys p {
|
565 |
+
# font-size: 1.1rem;
|
566 |
+
# line-height: 1.6;
|
567 |
+
# }
|
568 |
+
|
569 |
+
# /* Container for main content */
|
570 |
+
# .main-content {
|
571 |
+
# max-width: 1200px;
|
572 |
+
# margin: 0 auto;
|
573 |
+
# padding: 0 1rem;
|
574 |
+
# }
|
575 |
+
# </style>
|
576 |
+
# """, unsafe_allow_html=True)
|
577 |
+
|
578 |
+
# # Header section
|
579 |
+
# st.markdown("<h1 class='main-title'>π The Sport Chatbot</h1>", unsafe_allow_html=True)
|
580 |
+
# st.markdown("<h3 class='sub-title'>Using ESPN API</h3>", unsafe_allow_html=True)
|
581 |
+
# st.markdown("""
|
582 |
+
# <p class='description'>
|
583 |
+
# Hey there! π I can help you with information on Ice Hockey, Baseball, American Football, Soccer, and Basketball.
|
584 |
+
# With access to the ESPN API, I'm up to date with the latest details for these sports up until October 2024.
|
585 |
+
# </p>
|
586 |
+
# <p class='description'>
|
587 |
+
# Got any general questions? Feel free to askβI'll do my best to provide answers based on the information I've been trained on!
|
588 |
+
# </p>
|
589 |
+
# """, unsafe_allow_html=True)
|
590 |
+
|
591 |
+
# # Initialize the pipeline with better error handling
|
592 |
+
# if 'rag' not in st.session_state:
|
593 |
+
# try:
|
594 |
+
# with st.spinner("Loading resources..."):
|
595 |
+
# st.session_state.rag = initialize_rag_pipeline()
|
596 |
+
# logging.info("Pipeline initialized successfully")
|
597 |
+
# except Exception as e:
|
598 |
+
# logging.error(f"Pipeline initialization error: {str(e)}")
|
599 |
+
# st.error("Failed to initialize the system. Please check the logs.")
|
600 |
+
# st.stop()
|
601 |
+
# return
|
602 |
+
|
603 |
+
# # Create columns for layout
|
604 |
+
# col1, col2, col3 = st.columns([1, 6, 1])
|
605 |
+
|
606 |
+
# with col2:
|
607 |
+
# # Query input
|
608 |
+
# query = st.text_input("What would you like to know about sports?")
|
609 |
+
|
610 |
+
# if st.button("Get Answer"):
|
611 |
+
# if query:
|
612 |
+
# response_placeholder = st.empty()
|
613 |
+
# try:
|
614 |
+
# # Log query processing start
|
615 |
+
# logging.info(f"Processing query: {query}")
|
616 |
+
|
617 |
+
# # Process query and get response
|
618 |
+
# response = st.session_state.rag.process_query(query, response_placeholder)
|
619 |
+
|
620 |
+
# # Log successful response
|
621 |
+
# logging.info(f"Generated response: {response}")
|
622 |
+
# except Exception as e:
|
623 |
+
# # Log error details
|
624 |
+
# logging.error(f"Query processing error: {str(e)}")
|
625 |
+
# logging.error("Full error details: ", exc_info=True)
|
626 |
+
# response_placeholder.warning("Unable to process your question. Please try again.")
|
627 |
+
# else:
|
628 |
+
# st.warning("Please enter a question!")
|
629 |
+
|
630 |
+
# # Footer
|
631 |
+
# st.markdown("<br><br>", unsafe_allow_html=True)
|
632 |
+
# st.markdown("---")
|
633 |
+
# st.markdown("""
|
634 |
+
# <p style='text-align: center; color: #666666; padding: 1rem 0;'>
|
635 |
+
# Powered by ESPN Data & Mistral AI π
|
636 |
+
# </p>
|
637 |
+
# """, unsafe_allow_html=True)
|
638 |
+
|
639 |
+
# except Exception as e:
|
640 |
+
# logging.error(f"Application error: {str(e)}")
|
641 |
+
# logging.error("Full error details: ", exc_info=True)
|
642 |
+
# st.error("An unexpected error occurred. Please check the logs and try again.")
|
643 |
+
|
644 |
+
# if __name__ == "__main__":
|
645 |
+
# # Configure logging
|
646 |
+
# logging.basicConfig(
|
647 |
+
# level=logging.INFO,
|
648 |
+
# format='%(asctime)s - %(levelname)s - %(message)s'
|
649 |
+
# )
|
650 |
+
|
651 |
+
# try:
|
652 |
+
# main()
|
653 |
+
# except Exception as e:
|
654 |
+
# logging.error(f"Fatal error: {str(e)}")
|
655 |
+
# logging.error("Full error details: ", exc_info=True)
|
656 |
+
# st.error("A fatal error occurred. Please check the logs and try again.")
|
657 |
+
|
658 |
+
# if __name__ == "__main__":
|
659 |
+
# main()
|
660 |
+
|
661 |
+
|
662 |
def main():
|
663 |
try:
|
664 |
# Environment check
|
|
|
735 |
</style>
|
736 |
""", unsafe_allow_html=True)
|
737 |
|
738 |
+
# Header section with unique keys
|
739 |
+
st.markdown("<h1 class='main-title'>π The Sport Chatbot</h1>", unsafe_allow_html=True, key="title")
|
740 |
+
st.markdown("<h3 class='sub-title'>Using ESPN API</h3>", unsafe_allow_html=True, key="subtitle")
|
741 |
st.markdown("""
|
742 |
<p class='description'>
|
743 |
Hey there! π I can help you with information on Ice Hockey, Baseball, American Football, Soccer, and Basketball.
|
744 |
With access to the ESPN API, I'm up to date with the latest details for these sports up until October 2024.
|
745 |
</p>
|
746 |
+
""", unsafe_allow_html=True, key="desc1")
|
747 |
+
|
748 |
+
st.markdown("""
|
749 |
<p class='description'>
|
750 |
Got any general questions? Feel free to askβI'll do my best to provide answers based on the information I've been trained on!
|
751 |
</p>
|
752 |
+
""", unsafe_allow_html=True, key="desc2")
|
753 |
+
|
754 |
+
# Add spacing
|
755 |
+
st.markdown("<br>", unsafe_allow_html=True, key="spacing1")
|
756 |
|
757 |
# Initialize the pipeline with better error handling
|
758 |
if 'rag' not in st.session_state:
|
|
|
762 |
logging.info("Pipeline initialized successfully")
|
763 |
except Exception as e:
|
764 |
logging.error(f"Pipeline initialization error: {str(e)}")
|
765 |
+
st.error("Failed to initialize the system. Please check the logs.", key="init_error")
|
766 |
st.stop()
|
767 |
return
|
768 |
|
|
|
770 |
col1, col2, col3 = st.columns([1, 6, 1])
|
771 |
|
772 |
with col2:
|
773 |
+
# Query input with unique key
|
774 |
+
query = st.text_input(
|
775 |
+
"What would you like to know about sports?",
|
776 |
+
key="sports_query"
|
777 |
+
)
|
778 |
|
779 |
+
# Centered button with unique key
|
780 |
+
if st.button("Get Answer", key="answer_button"):
|
781 |
if query:
|
782 |
response_placeholder = st.empty()
|
783 |
try:
|
784 |
# Log query processing start
|
785 |
logging.info(f"Processing query: {query}")
|
786 |
|
787 |
+
with st.spinner("Processing your question..."):
|
788 |
+
# Process query and get response
|
789 |
+
response = st.session_state.rag.process_query(query, response_placeholder)
|
790 |
+
|
791 |
+
# Log successful response
|
792 |
+
logging.info(f"Generated response: {response}")
|
793 |
+
|
794 |
except Exception as e:
|
795 |
# Log error details
|
796 |
logging.error(f"Query processing error: {str(e)}")
|
797 |
logging.error("Full error details: ", exc_info=True)
|
798 |
+
response_placeholder.warning(
|
799 |
+
"Unable to process your question. Please try again.",
|
800 |
+
key="query_error"
|
801 |
+
)
|
802 |
else:
|
803 |
+
st.warning("Please enter a question!", key="empty_query_warning")
|
804 |
|
805 |
+
# Footer with unique keys
|
806 |
+
st.markdown("<br><br>", unsafe_allow_html=True, key="spacing2")
|
807 |
+
st.markdown("---", key="divider")
|
808 |
st.markdown("""
|
809 |
<p style='text-align: center; color: #666666; padding: 1rem 0;'>
|
810 |
Powered by ESPN Data & Mistral AI π
|
811 |
</p>
|
812 |
+
""", unsafe_allow_html=True, key="footer")
|
813 |
|
814 |
except Exception as e:
|
815 |
logging.error(f"Application error: {str(e)}")
|
816 |
logging.error("Full error details: ", exc_info=True)
|
817 |
+
st.error(
|
818 |
+
"An unexpected error occurred. Please check the logs and try again.",
|
819 |
+
key="main_error"
|
820 |
+
)
|
821 |
|
822 |
if __name__ == "__main__":
|
823 |
# Configure logging
|
|
|
831 |
except Exception as e:
|
832 |
logging.error(f"Fatal error: {str(e)}")
|
833 |
logging.error("Full error details: ", exc_info=True)
|
834 |
+
st.error(
|
835 |
+
"A fatal error occurred. Please check the logs and try again.",
|
836 |
+
key="fatal_error"
|
837 |
+
)
|