| | import streamlit as st |
| | import PyPDF2 |
| | import google.generativeai as genai |
| |
|
| | |
| | GEMINI_API_KEY = "AIzaSyAJ9xJ83VSmJoyVXmplPw-HaDkBfro-jiM" |
| | genai.configure(api_key=GEMINI_API_KEY) |
| |
|
| | |
| | model = genai.GenerativeModel('gemini-pro') |
| |
|
| | |
| | def extract_text_from_pdf(pdf_file): |
| | reader = PyPDF2.PdfReader(pdf_file) |
| | text = "" |
| | for page in reader.pages: |
| | text += page.extract_text() |
| | return text |
| |
|
| | |
| | def summarize_text(text): |
| | prompt = f"Summarize the following research paper in 200 words:\n\n{text}" |
| | response = model.generate_content(prompt) |
| | return response.text |
| |
|
| | |
| | def answer_question(text, question): |
| | prompt = f"Based on the following research paper, answer the question:\n\n{text}\n\nQuestion: {question}" |
| | response = model.generate_content(prompt) |
| | return response.text |
| |
|
| | |
| | def main(): |
| | st.title("Haroon Research Paper Summarizer") |
| | st.write("Upload a research paper in PDF format, and I'll summarize it and answer your questions!") |
| |
|
| | |
| | uploaded_file = st.file_uploader("Upload a PDF file", type="pdf") |
| |
|
| | if uploaded_file is not None: |
| | |
| | text = extract_text_from_pdf(uploaded_file) |
| | st.success("PDF uploaded and text extracted successfully!") |
| |
|
| | |
| | st.subheader("Summary of the Research Paper") |
| | summary = summarize_text(text) |
| | st.write(summary) |
| |
|
| | |
| | st.subheader("Ask Questions About the Research Paper") |
| | question = st.text_input("Type your question here:") |
| | if question: |
| | answer = answer_question(text, question) |
| | st.write("**Answer:**") |
| | st.write(answer) |
| |
|
| | if __name__ == "__main__": |
| | main() |