Markndrei's picture
Uploading my Application files and requirements.
a0e70aa
import streamlit as st
import os
import google.generativeai as genai
from PyPDF2 import PdfReader
# Gemini Model Initialization
MODEL_ID = "gemini-2.0-flash-exp"
api_key = os.getenv("GEMINI_API_KEY")
genai.configure(api_key=api_key)
model = genai.GenerativeModel(MODEL_ID)
chat = model.start_chat()
st.title("πŸ“š Smart VQA Thesis Analysis")
with st.expander("πŸ“– **What is this app about?**"):
st.write("""
The **Smart VQA Thesis Analysis** app is an AI-powered tool designed to help users extract valuable insights from thesis documents.
By leveraging **Gemini 2.0's Flash Experimental Model**, this intelligent system allows users to interactively engage with their documents,
making research and information retrieval more efficient.
Instead of manually searching through lengthy PDFs, users can simply upload their thesis and ask questions. The AI will analyze the document and
generate contextually relevant responses, providing concise summaries, clarifications, and deeper insights.
""")
with st.expander("βš™οΈ **How does it work?**"):
st.write("""
The application follows a simple three-step process:
1. **Upload a PDF thesis document**
- Click the upload button and select your PDF file. The app processes the document and extracts text for analysis.
2. **Ask a question about the document**
- Type in any question related to the uploaded thesis. The AI will analyze the document's content to generate an answer.
3. **Receive AI-generated responses**
- The system intelligently retrieves and summarizes relevant sections of the document to provide a clear and concise response.
This approach helps users quickly extract information without having to manually browse through numerous pages.
""")
with st.expander("πŸ” **What kind of questions can I ask?**"):
st.write("""
This AI-powered system is designed to understand a wide range of inquiries. You can ask questions such as:
- **Key arguments and conclusions**: *What is the main argument of this thesis?*
- **Summarization of sections**: *Can you summarize Chapter 3?*
- **Definition of terms**: *What does "computational linguistics" mean in this context?*
- **Comparison of ideas**: *How does this study relate to previous research?*
- **Explanations of methodologies**: *What research methods were used in this thesis?*
- **Data interpretations**: *What are the key findings from the analysis section?*
- **Theoretical frameworks**: *What theories support the thesis argument?*
Whether you're reviewing a thesis, verifying research findings, or seeking clarification, this AI-driven tool makes document analysis faster and more accessible.
""")
# Upload Section
st.header("Upload Thesis file")
uploaded_file = st.file_uploader("Upload a PDF file to be analyzed", type=["pdf"])
# Check if file is uploaded or removed
if uploaded_file:
pdf_reader = PdfReader(uploaded_file)
thesis_text = "\n".join([page.extract_text() for page in pdf_reader.pages if page.extract_text()])
st.session_state["thesis_text"] = thesis_text
st.success("Thesis uploaded successfully!")
else:
st.session_state.pop("thesis_text", None) # Remove document text if no file is uploaded
# Only show the question input if a document is uploaded
if "thesis_text" in st.session_state:
st.header("Ask AI About Your Document")
def ask_ai(question):
"""Process user question with the uploaded document."""
try:
prompt = f"Analyze the following document and answer: {question}\n\nDocument Content:\n{st.session_state['thesis_text'][:5000]}"
response = chat.send_message(prompt)
return response.text
except Exception as e:
return f"Error: {e}"
selected_question = st.text_input("Enter your question about the document contents:")
if st.button("Generate Answer") and selected_question:
with st.spinner("AI is reading the document..."):
response = ask_ai(selected_question)
st.markdown(f"**Response:** \n {response}")
else:
st.warning("Please upload a thesis document to proceed.")
st.markdown("© 2025 Mandrei :3 ✨")