Spaces:
Sleeping
Sleeping
Commit ·
b79ae95
1
Parent(s): e2afab9
Update gradio_chatwithpdf.py
Browse files- gradio_chatwithpdf.py +4 -7
gradio_chatwithpdf.py
CHANGED
|
@@ -1,20 +1,17 @@
|
|
| 1 |
|
| 2 |
from openai import OpenAI
|
| 3 |
import gradio
|
| 4 |
-
import shutil
|
| 5 |
import pdfplumber
|
| 6 |
import os
|
| 7 |
-
import
|
| 8 |
|
| 9 |
def read_PDF_2(fileobj):
|
| 10 |
print("readPDF called")
|
| 11 |
pdf_text = ""
|
| 12 |
|
| 13 |
-
|
| 14 |
-
path = os.path.join(temp_dir, os.path.basename(fileobj.name))
|
| 15 |
-
shutil.copyfile(fileobj.name, path)
|
| 16 |
|
| 17 |
-
with pdfplumber.open(
|
| 18 |
for page in pdf.pages:
|
| 19 |
pdf_text += page.extract_text()
|
| 20 |
|
|
@@ -41,7 +38,7 @@ def askPDF(upload_PDF, prompt):
|
|
| 41 |
|
| 42 |
# gradio deployment
|
| 43 |
demo = gradio.Interface(fn=askPDF,
|
| 44 |
-
inputs=[gradio.File(file_types=['.pdf']), 'text'],
|
| 45 |
outputs="text",
|
| 46 |
)
|
| 47 |
|
|
|
|
| 1 |
|
| 2 |
from openai import OpenAI
|
| 3 |
import gradio
|
|
|
|
| 4 |
import pdfplumber
|
| 5 |
import os
|
| 6 |
+
from io import BytesIO
|
| 7 |
|
| 8 |
def read_PDF_2(fileobj):
|
| 9 |
print("readPDF called")
|
| 10 |
pdf_text = ""
|
| 11 |
|
| 12 |
+
pdf_file = BytesIO(fileobj)
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
with pdfplumber.open(pdf_file) as pdf:
|
| 15 |
for page in pdf.pages:
|
| 16 |
pdf_text += page.extract_text()
|
| 17 |
|
|
|
|
| 38 |
|
| 39 |
# gradio deployment
|
| 40 |
demo = gradio.Interface(fn=askPDF,
|
| 41 |
+
inputs=[gradio.File(type = "binary",file_types=['.pdf']), 'text'],
|
| 42 |
outputs="text",
|
| 43 |
)
|
| 44 |
|