# Configure page settings (MUST BE FIRST STREAMLIT COMMAND) import streamlit as st from streamlit_option_menu import option_menu from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM, AutoModelForDocumentQuestionAnswering from PyPDF2 import PdfReader # Set page config st.set_page_config( page_title="Disease Analysis GPT", layout="wide", initial_sidebar_state="expanded" ) # Load Hugging Face models and tokenizer for text generation @st.cache_resource def load_model(): tokenizer = AutoTokenizer.from_pretrained("harishussain12/Disease_Managment") model = AutoModelForCausalLM.from_pretrained("harishussain12/Disease_Managment") return tokenizer, model # Load Hugging Face models and tokenizer for document question answering @st.cache_resource def load_document_model(): tokenizer = AutoTokenizer.from_pretrained("harishussain12/File_Reader") model = AutoModelForDocumentQuestionAnswering.from_pretrained("harishussain12/File_Reader") return tokenizer, model # Function to create a text generation pipeline @st.cache_resource def create_pipeline(): tokenizer, model = load_model() return pipeline("text-generation", model=model, tokenizer=tokenizer) # Function to create a document question answering pipeline @st.cache_resource def create_document_pipeline(): tokenizer, model = load_document_model() return pipeline("document-question-answering", model=model, tokenizer=tokenizer) # Function to extract text from PDF file def read_pdf(file): try: reader = PdfReader(file) text = "" for page in reader.pages: text += page.extract_text() return text except Exception as e: return f"Error reading PDF: {e}" # Load pipelines text_pipeline = create_pipeline() document_pipeline = create_document_pipeline() # Custom CSS for styling st.markdown( """ """, unsafe_allow_html=True ) # Sidebar with st.sidebar: new_chat_button = st.button("New Chat", key="new_chat", help="Start a new chat to ask a different question.") if new_chat_button: st.session_state.clear() # Clear session state to simulate a new chat st.experimental_set_query_params() # Clear URL query params selected = option_menu( menu_title=None, options=[" Home", " Discover"], icons=["house", "search"], menu_icon="cast", default_index=0, styles={ "container": {"padding": "0!important", "background-color": "#3e4a5b"}, "icon": {"color": "#ffffff", "font-size": "16px"}, "nav-link": { "font-size": "15px", "text-align": "left", "margin": "0px", "color": "#ffffff", "font-weight": "bold", "padding": "10px 20px", }, "nav-link-selected": {"background-color": "#0b2545", "color": "white"}, } ) # Main content col1, col2, col3 = st.columns([1, 2, 1]) with col2: st.markdown("