import streamlit as st import google.generativeai as genai import os # Replace with your actual API key api_key = os.getenv("GEMINI_API_KEY") genai.configure(api_key=api_key) def multimodal_prompt(pdf_file, text_prompt): """ Sends a multimodal prompt to the Gemini model with a PDF and text. Args: pdf_file: The uploaded PDF file object. text_prompt: The text prompt. Returns: The model's response as a string. """ model = genai.GenerativeModel("gemini-1.5-flash") try: # Upload the PDF file pdf_file = genai.upload_file(pdf_file, mime_type="application/pdf") # Construct the prompt with the uploaded file and text prompt = [ text_prompt, pdf_file ] # Send the request to the model response = model.generate_content(prompt) return response.text except Exception as e: return f"An error occurred: {e}" # Streamlit UI st.title("Research Paper Summarization with Gemini AI") with st.expander("ℹ️ About"): st.write( "This app demonstrates how to use the Gemini API to generate multimodal content. " "You can upload a PDF file and provide a text prompt to summarize the content." ) st.write("Ptogrammed by Louie F. Cervantes, M. Eng. (Information Engineering)") st.write("Department of Computer Science, College of Inormation and Communications") st.write("West Visayas State University, La Paz, Iloilo City, Philippines") # Task selection dropdown summarization_tasks = [ "Extract the research paper's title, authors, and publication year.", "Summarize the main objectives or goals of this research study.", "Identify the research methodology or approach used in the study.", "List the key findings or results presented in the paper.", "Extract the research question or hypothesis being investigated.", "Summarize the significance or impact of the research findings.", "List the main keywords or concepts discussed in the paper.", "Provide a brief summary of the literature review or background section.", "Highlight the conclusion and recommendations provided by the authors.", "Identify any limitations or future research directions mentioned in the paper." ] st.subheader("Select a Summarization Task") selected_task = st.selectbox("Choose a task from the list:", ["Custom Prompt"] + summarization_tasks) st.subheader("Or Enter a Custom Prompt") custom_prompt = st.text_input("Enter your custom prompt:") # Combine the selected task and custom prompt text_prompt = custom_prompt if selected_task == "Custom Prompt" else selected_task # File uploader for PDF uploaded_file = st.file_uploader("Choose a PDF file", type="pdf") if uploaded_file is not None and text_prompt: if st.button("Submit"): with st.spinner("Processing..."): response = multimodal_prompt(uploaded_file, text_prompt) st.write(response)