Spaces:
Sleeping
Sleeping
File size: 1,057 Bytes
2d71bf6 0669fa1 2d71bf6 30fd9a1 2d71bf6 0669fa1 2d71bf6 0669fa1 2d71bf6 0669fa1 |
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 |
import gradio as gr
import PyPDF2
import io
# PDF ํ์ผ์์ ํ
์คํธ๋ฅผ ์ถ์ถํ๋ ํจ์
def extract_text_from_pdf(pdf_file):
reader = PyPDF2.PdfFileReader(io.BytesIO(pdf_file.read()))
text = ""
for page in range(reader.numPages):
text += reader.getPage(page).extractText()
return text
# ์ถ์ถ๋ ํ
์คํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ง๋ฌธ์ ๋ต๋ณํ๋ ํจ์
def answer_question(extracted_text, question):
# ์ฌ๊ธฐ์์๋ ๊ฐ๋จํ๊ฒ ํ
์คํธ์์ ์ง๋ฌธ๊ณผ ์ ์ฌํ ๋ถ๋ถ์ ์ฐพ์ ๋ฐํํฉ๋๋ค.
# ๋ณด๋ค ๋ณต์กํ ๋ก์ง์ ๊ตฌํํ ์๋ ์์ต๋๋ค.
if question in extracted_text:
start = extracted_text.find(question)
end = extracted_text.find('.', start) + 1
return extracted_text[start:end]
else:
return "์ง๋ฌธ์ ๋ํ ๋ต๋ณ์ ์ฐพ์ ์ ์์ต๋๋ค."
# Gradio ์ธํฐํ์ด์ค ์ ์
iface = gr.Interface(
fn=answer_question,
inputs=[gr.inputs.Textbox(label="PDF ๋ด์ฉ"), gr.inputs.Textbox(label="์ง๋ฌธ")],
outputs="text"
)
iface.launch()
|