-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp-streamlit.py
49 lines (39 loc) · 1.43 KB
/
app-streamlit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from flask import Flask, render_template, request, jsonify
from flask_ngrok import run_with_ngrok
from io import BytesIO
from PyPDF2 import PdfReader
import google.generativeai as palm
import streamlit as st
app = Flask(__name__)
# run_with_ngrok(app)
palm.configure(api_key='AIzaSyATloJFmBEnswSVQf1oOMA3L5F3azDztCE')
def process_pdf(pdf_data):
if pdf_data:
reader = PdfReader(BytesIO(pdf_data))
txt = ""
summary = ""
count=0;
st.write("Reading page: ",count,"/",len(reader.pages))
for i in range(len(reader.pages)):
page = reader.pages[i]
txt = page.extract_text()
st.write(i, "/", len(reader.pages))
count=i
pt = 'Generate the summary of the following text in atleast 100 words and suggest health precautions that patient should change\n' + txt
response = palm.generate_text(prompt=pt)
print(f"{response.result}\n\n")
if response.result:
summary += response.result + "\n\n"
# print(txt)
if summary != "":
return summary
return 'Failed to process the PDF'
def main():
summary = "Error"
file = st.file_uploader("Choose a file", type = "pdf")
if st.button("Predict"):
if file:
summary = process_pdf(pdf_data=file.getvalue())
st.success('The output is {}'.format(summary))
if __name__ == '__main__':
main()