Spaces:
Sleeping
Sleeping
juniorjukeko
commited on
Commit
•
b6b3547
1
Parent(s):
c18e1b1
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,8 @@ import gradio as gr
|
|
13 |
title = '''
|
14 |
<div style="text-align: left; font-family:Arial; color:Black; font-size: 16px; max-width: 750px;">
|
15 |
<h1>Small PDF Summarizer</h1>
|
16 |
-
<p style="text-align: left;">
|
|
|
17 |
1. Upload a .PDF from your computer and fill OpenAI API key.<br/>
|
18 |
2. Click the "Upload PDF" button, if successful a preview of your PDF text will be shown.<br/>
|
19 |
3. Click "Summarize!" and the output will be shown on the textbox bellow.<br/>
|
@@ -58,36 +59,6 @@ model_list = {'gpt-3.5-turbo':'chat',
|
|
58 |
'text-davinci-003':'instruct'}
|
59 |
|
60 |
text_splitter = RecursiveCharacterTextSplitter(separators=["\n\n", "\n"], chunk_size=10000, chunk_overlap=250)
|
61 |
-
|
62 |
-
# def parse_pdf(file_path):
|
63 |
-
# output = []
|
64 |
-
# print(file_path)
|
65 |
-
# pdf = PdfReader(file_path)
|
66 |
-
|
67 |
-
# for page in pdf.pages:
|
68 |
-
# text = page.extract_text()
|
69 |
-
# output.append(text)
|
70 |
-
|
71 |
-
# return output, len(pdf.pages)
|
72 |
-
|
73 |
-
# def preprocess_pdf_text(pdf_file): #(list_of_text):
|
74 |
-
# global page_num
|
75 |
-
|
76 |
-
# pdf_txt, page_num = parse_pdf(pdf_file.name)
|
77 |
-
# file_check(pdf_file.name)
|
78 |
-
|
79 |
-
# page_docs = [Document(page_content=page) for page in pdf_txt]
|
80 |
-
|
81 |
-
# text_splitter = RecursiveCharacterTextSplitter(separators=["\n\n", "\n"], chunk_size=250, chunk_overlap=50)
|
82 |
-
# doc_sections = []
|
83 |
-
# for page in page_docs:
|
84 |
-
# sections_text = text_splitter.split_text(page.page_content)
|
85 |
-
# sections_doc = [Document(page_content=section) for section in sections_text]
|
86 |
-
|
87 |
-
# for section in sections_doc:
|
88 |
-
# doc_sections.append(section)
|
89 |
-
|
90 |
-
# return doc_sections
|
91 |
|
92 |
def parse_pdf(pdf_file):
|
93 |
global pdf_docs, page_count
|
@@ -110,7 +81,12 @@ def file_check(pdf_file):
|
|
110 |
def summarize_pdf(api_key,
|
111 |
model_name, temperature, llm_max_tokens,
|
112 |
custom_map_prompt, custom_combine_prompt):
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
114 |
# Build LLM Model
|
115 |
os.environ["OPENAI_API_KEY"] = api_key
|
116 |
if model_list[model_name] == 'chat':
|
@@ -185,11 +161,10 @@ def main():
|
|
185 |
prompt_preview_button.click(generate_template, inputs=[user_map_prompt], outputs=[custom_map_view])
|
186 |
prompt_preview_button.click(generate_template, inputs=[user_comb_prompt], outputs=[custom_comb_view])
|
187 |
|
188 |
-
|
189 |
-
|
190 |
-
# summarize_click = summarize_button.click(preprocess_pdf_text, inputs=[pdf_doc], outputs=[ingest_pdf]).\
|
191 |
-
# then(summarize_pdf, inputs=list_inputs, outputs=[summarized_text])
|
192 |
submit_button.click(parse_pdf, inputs=[pdf_doc], outputs=[pdf_preview])
|
|
|
193 |
|
194 |
demo.queue(concurrency_count=1).launch(share=True)
|
195 |
|
|
|
13 |
title = '''
|
14 |
<div style="text-align: left; font-family:Arial; color:Black; font-size: 16px; max-width: 750px;">
|
15 |
<h1>Small PDF Summarizer</h1>
|
16 |
+
<p style="text-align: left;">This App can be used to summarize small PDF (max. 1 MB, 15 pages)<br/>
|
17 |
+
How to Use:<br/>
|
18 |
1. Upload a .PDF from your computer and fill OpenAI API key.<br/>
|
19 |
2. Click the "Upload PDF" button, if successful a preview of your PDF text will be shown.<br/>
|
20 |
3. Click "Summarize!" and the output will be shown on the textbox bellow.<br/>
|
|
|
59 |
'text-davinci-003':'instruct'}
|
60 |
|
61 |
text_splitter = RecursiveCharacterTextSplitter(separators=["\n\n", "\n"], chunk_size=10000, chunk_overlap=250)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
def parse_pdf(pdf_file):
|
64 |
global pdf_docs, page_count
|
|
|
81 |
def summarize_pdf(api_key,
|
82 |
model_name, temperature, llm_max_tokens,
|
83 |
custom_map_prompt, custom_combine_prompt):
|
84 |
+
try:
|
85 |
+
if pdf_docs[0].page_content[:1]:
|
86 |
+
pass
|
87 |
+
except:
|
88 |
+
raise gr.Error("No PDF File Detected!")
|
89 |
+
|
90 |
# Build LLM Model
|
91 |
os.environ["OPENAI_API_KEY"] = api_key
|
92 |
if model_list[model_name] == 'chat':
|
|
|
161 |
prompt_preview_button.click(generate_template, inputs=[user_map_prompt], outputs=[custom_map_view])
|
162 |
prompt_preview_button.click(generate_template, inputs=[user_comb_prompt], outputs=[custom_comb_view])
|
163 |
|
164 |
+
inputs_list = [API_KEY, llm_model, temperature, llm_max_tokens, user_map_prompt, user_comb_prompt]
|
165 |
+
|
|
|
|
|
166 |
submit_button.click(parse_pdf, inputs=[pdf_doc], outputs=[pdf_preview])
|
167 |
+
summarize_button.click(summarize_pdf, inputs=inputs_list, outputs=[summarized_text])
|
168 |
|
169 |
demo.queue(concurrency_count=1).launch(share=True)
|
170 |
|