seawolf2357 commited on
Commit
b30eb63
ยท
verified ยท
1 Parent(s): a254eb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
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.read()))
8
  text = ""
9
  for page in range(reader.numPages):
10
  text += reader.getPage(page).extractText()
11
  return text
12
 
13
  # ์ถ”์ถœ๋œ ํ…์ŠคํŠธ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์งˆ๋ฌธ์— ๋‹ต๋ณ€ํ•˜๋Š” ํ•จ์ˆ˜
14
- def answer_question(extracted_text, 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.inputs.Textbox(label="PDF ๋‚ด์šฉ"), gr.inputs.Textbox(label="์งˆ๋ฌธ")],
28
- outputs="text"
29
  )
30
 
31
- iface.launch()
 
 
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()