Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,14 +4,15 @@ import io
|
|
4 |
|
5 |
# PDF ํ์ผ์์ ํ
์คํธ๋ฅผ ์ถ์ถํ๋ ํจ์
|
6 |
def extract_text_from_pdf(pdf_file):
|
7 |
-
reader = PyPDF2.PdfFileReader(io.BytesIO(pdf_file
|
8 |
text = ""
|
9 |
for page in range(reader.numPages):
|
10 |
text += reader.getPage(page).extractText()
|
11 |
return text
|
12 |
|
13 |
# ์ถ์ถ๋ ํ
์คํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ง๋ฌธ์ ๋ต๋ณํ๋ ํจ์
|
14 |
-
def answer_question(
|
|
|
15 |
# ์ฌ๊ธฐ์์๋ ๊ฐ๋จํ๊ฒ ํ
์คํธ์์ ์ง๋ฌธ๊ณผ ์ ์ฌํ ๋ถ๋ถ์ ์ฐพ์ ๋ฐํํฉ๋๋ค.
|
16 |
# ๋ณด๋ค ๋ณต์กํ ๋ก์ง์ ๊ตฌํํ ์๋ ์์ต๋๋ค.
|
17 |
if question in extracted_text:
|
@@ -24,8 +25,9 @@ def answer_question(extracted_text, question):
|
|
24 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
25 |
iface = gr.Interface(
|
26 |
fn=answer_question,
|
27 |
-
inputs=[gr.
|
28 |
-
outputs=
|
29 |
)
|
30 |
|
31 |
-
|
|
|
|
4 |
|
5 |
# PDF ํ์ผ์์ ํ
์คํธ๋ฅผ ์ถ์ถํ๋ ํจ์
|
6 |
def extract_text_from_pdf(pdf_file):
|
7 |
+
reader = PyPDF2.PdfFileReader(io.BytesIO(pdf_file))
|
8 |
text = ""
|
9 |
for page in range(reader.numPages):
|
10 |
text += reader.getPage(page).extractText()
|
11 |
return text
|
12 |
|
13 |
# ์ถ์ถ๋ ํ
์คํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ง๋ฌธ์ ๋ต๋ณํ๋ ํจ์
|
14 |
+
def answer_question(pdf_file, question):
|
15 |
+
extracted_text = extract_text_from_pdf(pdf_file)
|
16 |
# ์ฌ๊ธฐ์์๋ ๊ฐ๋จํ๊ฒ ํ
์คํธ์์ ์ง๋ฌธ๊ณผ ์ ์ฌํ ๋ถ๋ถ์ ์ฐพ์ ๋ฐํํฉ๋๋ค.
|
17 |
# ๋ณด๋ค ๋ณต์กํ ๋ก์ง์ ๊ตฌํํ ์๋ ์์ต๋๋ค.
|
18 |
if question in extracted_text:
|
|
|
25 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
26 |
iface = gr.Interface(
|
27 |
fn=answer_question,
|
28 |
+
inputs=[gr.File(type="file"), gr.Textbox(label="์ง๋ฌธ")],
|
29 |
+
outputs=gr.Textbox()
|
30 |
)
|
31 |
|
32 |
+
# Launch the interface
|
33 |
+
iface.launch()
|