fickya87 commited on
Commit
28b1e07
·
verified ·
1 Parent(s): c55fe66

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +80 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import google.generativeai as genai
3
+ import os
4
+
5
+ # Replace with your actual API key
6
+ api_key = os.getenv("GEMINI_API_KEY")
7
+ genai.configure(api_key=api_key)
8
+
9
+ def multimodal_prompt(pdf_file, text_prompt):
10
+ """
11
+ Sends a multimodal prompt to the Gemini model with a PDF and text.
12
+
13
+ Args:
14
+ pdf_file: The uploaded PDF file object.
15
+ text_prompt: The text prompt.
16
+
17
+ Returns:
18
+ The model's response as a string.
19
+ """
20
+ model = genai.GenerativeModel("gemini-1.5-flash")
21
+
22
+ try:
23
+ # Upload the PDF file
24
+ pdf_file = genai.upload_file(pdf_file, mime_type="application/pdf")
25
+
26
+ # Construct the prompt with the uploaded file and text
27
+ prompt = [
28
+ text_prompt,
29
+ pdf_file
30
+ ]
31
+
32
+ # Send the request to the model
33
+ response = model.generate_content(prompt)
34
+ return response.text
35
+ except Exception as e:
36
+ return f"An error occurred: {e}"
37
+
38
+ # Streamlit UI
39
+ st.title("Research Paper Summarization with Gemini AI")
40
+
41
+ with st.expander("ℹ️ About"):
42
+ st.write(
43
+ "This app demonstrates how to use the Gemini API to generate multimodal content. "
44
+ "You can upload a PDF file and provide a text prompt to summarize the content."
45
+ )
46
+ st.write("Ptogrammed by Louie F. Cervantes, M. Eng. (Information Engineering)")
47
+ st.write("Department of Computer Science, College of Inormation and Communications")
48
+ st.write("West Visayas State University, La Paz, Iloilo City, Philippines")
49
+
50
+ # Task selection dropdown
51
+ summarization_tasks = [
52
+ "Extract the research paper's title, authors, and publication year.",
53
+ "Summarize the main objectives or goals of this research study.",
54
+ "Identify the research methodology or approach used in the study.",
55
+ "List the key findings or results presented in the paper.",
56
+ "Extract the research question or hypothesis being investigated.",
57
+ "Summarize the significance or impact of the research findings.",
58
+ "List the main keywords or concepts discussed in the paper.",
59
+ "Provide a brief summary of the literature review or background section.",
60
+ "Highlight the conclusion and recommendations provided by the authors.",
61
+ "Identify any limitations or future research directions mentioned in the paper."
62
+ ]
63
+
64
+ st.subheader("Select a Summarization Task")
65
+ selected_task = st.selectbox("Choose a task from the list:", ["Custom Prompt"] + summarization_tasks)
66
+
67
+ st.subheader("Or Enter a Custom Prompt")
68
+ custom_prompt = st.text_input("Enter your custom prompt:")
69
+
70
+ # Combine the selected task and custom prompt
71
+ text_prompt = custom_prompt if selected_task == "Custom Prompt" else selected_task
72
+
73
+ # File uploader for PDF
74
+ uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
75
+
76
+ if uploaded_file is not None and text_prompt:
77
+ if st.button("Submit"):
78
+ with st.spinner("Processing..."):
79
+ response = multimodal_prompt(uploaded_file, text_prompt)
80
+ st.write(response)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ google-generativeai