Spaces:
Sleeping
Sleeping
Update app.py
Browse files56 unmodified lines5758596061626348 unmodified lines11211311411511611711811912012112212312412512612712812913013113213345 unmodified lines17918018118218318418561 unmodified lines24724824925025125225325425525625725825926026126226326410 unmodified lines27527627756 unmodified lines# Function to split text into manageable chunksdef split_text(text, max_chunk_size=2000):"""Split text into chunks with a maximum size."""chunks = []while len(text) > max_chunk_size:chunk = text[:max_chunk_size]48 unmodified linesbyte_io.seek(0)return byte_io# Streamlit Appst.set_page_config(page_title="Interactify")page = st.sidebar.radio("Select Page", ["Home", "History"])if page == "Home":st.title("Interactify")# Dropdown for subject selectionsubject = st.selectbox("Select Subject", ["Mathematics", "Statistics", "Computer Science"])# File uploader for slides (PDF, Word, PPT, or text) inputuploaded_file = st.file_uploader("Upload Your Document (PDF, DOCX, PPTX, TXT)...", type=["pdf", "docx", "pptx", "txt"])# Text area for user questionuser_question = st.text_area("Type your question about the document content:")# Text input for page rangepage_range_input = st.text_input("Enter page ranges (e.g., 78-79):")45 unmodified linespage_content = document_text[page_num]# Prepare prompt with extracted page textinput_prompt = input_prompts[subject]input_prompt_filled = input_prompt.format(page_content=page_content)# Get response from Gemini API61 unmodified linesmime='application/vnd.openxmlformats-officedocument.wordprocessingml.document')# Process user questionif user_question:question_prompt = f"Based on the content of the document, answer the following question:\n{user_question}"response = get_gemini_response(question_prompt)st.markdown("### Answer to Your Question:")st.write(response)except Exception as e:st.error(f"Error: {str(e)}")else:st.warning("Please upload your document.")elif page == "History":st.title("History")10 unmodified linesst.markdown("---")st.markdown("© 2024 by Christley")56 unmodified lines5758596061626348 unmodified lines11211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614745 unmodified lines19319419519619719819961 unmodified lines26126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630710 unmodified lines31831932032132232356 unmodified lines# Function to split text into manageable chunksdef split_text(text, max_chunk_size=2000):"""Split text into chunks with a maximum size."""chunks = []while len(text) > max_chunk_size:chunk = text[:max_chunk_size]48 unmodified linesbyte_io.seek(0)return byte_io# Define fields and subjectsfields_subjects = {"Law": ["Constitutional Law", "Criminal Law", "Contract Law", "Tort Law", "Property Law", "Family Law", "Administrative Law", "International Law", "Corporate Law", "Environmental Law"],"Science": ["Physics", "Chemistry", "Biology", "Geology", "Astronomy", "Ecology", "Botany", "Zoology", "Genetics", "Environmental Science"],"Medicine": ["Anatomy", "Physiology", "Pathology", "Pharmacology", "Microbiology", "Surgery", "Pediatrics", "Internal Medicine", "Psychiatry", "Radiology"],"Engineering": ["Civil Engineering", "Mechanical Engineering", "Electrical Engineering", "Chemical Engineering", "Aerospace Engineering", "Computer Engineering", "Environmental Engineering", "Industrial Engineering", "Structural Engineering", "Biomedical Engineering"],"Mathematics": ["Algebra", "Calculus", "Geometry", "Statistics", "Probability", "Number Theory", "Combinatorics", "Topology", "Differential Equations", "Mathematical Logic"],"Computer Science": ["Algorithms", "Data Structures", "Operating Systems", "Database Systems", "Networks", "Software Engineering", "Artificial Intelligence", "Machine Learning", "Human-Computer Interaction", "Computer Graphics"],"History": ["Ancient History", "Medieval History", "Modern History", "Economic History", "Military History", "Cultural History", "Political History", "Social History", "Intellectual History", "History of Science"],"Economics": ["Microeconomics", "Macroeconomics", "Econometrics", "Development Economics", "International Economics", "Labor Economics", "Public Economics", "Industrial Organization", "Behavioral Economics", "Environmental Economics"],"Psychology": ["Cognitive Psychology", "Developmental Psychology", "Clinical Psychology", "Social Psychology", "Industrial-Organizational Psychology", "Neuropsychology", "Health Psychology", "Forensic Psychology", "Educational Psychology", "Experimental Psychology"],"Education": ["Curriculum Development", "Educational Psychology", "Instructional Design", "Educational Technology", "Special Education", "Early Childhood Education", "Higher Education", "Adult Education", "Education Policy", "Comparative Education"]}# Streamlit Appst.set_page_config(page_title="Interactify")page = st.sidebar.radio("Select Page", ["Home", "Ask Me About Your Slides", "History"])if page == "Home":st.title("Interactify")# Dropdown for field selectionfield = st.selectbox("Select Field", list(fields_subjects.keys()))# Dropdown for subject selectionsubject = st.selectbox("Select Subject", fields_subjects[field])# File uploader for slides (PDF, Word, PPT, or text) inputuploaded_file = st.file_uploader("Upload Your Document (PDF, DOCX, PPTX, TXT)...", type=["pdf", "docx", "pptx", "txt"])# Text input for page rangepage_range_input = st.text_input("Enter page ranges (e.g., 78-79):")45 unmodified linespage_content = document_text[page_num]# Prepare prompt with extracted page textinput_prompt = input_prompts.get(subject, "")input_prompt_filled = input_prompt.format(page_content=page_content)# Get response from Gemini API61 unmodified linesmime='application/vnd.openxmlformats-officedocument.wordprocessingml.document')except Exception as e:st.error(f"Error: {str(e)}")else:st.warning("Please upload your document.")elif page == "Ask Me About Your Slides":st.title("Ask Me About Your Slides")# File uploader for slides (PDF, Word, PPT, or text) inputuploaded_file = st.file_uploader("Upload Your Document (PDF, DOCX, PPTX, TXT)...", type=["pdf", "docx", "pptx", "txt"])# Text area for user questionuser_question = st.text_area("Type your question about the document content:")if uploaded_file and user_question:try:# Extract text from the uploaded fileif uploaded_file.type == "application/pdf":document_text = input_pdf_text(uploaded_file)elif uploaded_file.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":document_text = input_word_text(uploaded_file)elif uploaded_file.type == "application/vnd.openxmlformats-officedocument.presentationml.presentation":document_text = input_ppt_text(uploaded_file)elif uploaded_file.type == "text/plain":document_text = uploaded_file.read().decode("utf-8").split('\n')else:st.error("Unsupported file type!")st.stop()# Combine all text for contextfull_text = "\n".join(document_text)question_prompt = f"Based on the content of the document, answer the following question:\n{user_question}\n\nDocument Content:\n{full_text}"response = get_gemini_response(question_prompt)st.markdown("### Answer to Your Question:")st.write(response)except Exception as e:st.error(f"Error: {str(e)}")else:st.warning("Please upload your document and enter your question.")elif page == "History":st.title("History")10 unmodified linesst.markdown("---")st.markdown("© 2024 by Christley")# Ensure formulas are rendered correctlyst.markdown("For LaTeX formula rendering, use `$` to surround inline formulas, and `$$` for display formulas.")
app.py+60-14