seawolf2357 commited on
Commit
bf2b986
ยท
verified ยท
1 Parent(s): a7a832c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -23
app.py CHANGED
@@ -1,31 +1,19 @@
1
  import gradio as gr
2
- import PyPDF2
3
- import io
4
 
5
- # PDF ํŒŒ์ผ์—์„œ ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•˜๋Š” ํ•จ์ˆ˜
6
- def extract_text_from_pdf(pdf_file):
7
- reader = PyPDF2.PdfReader(io.BytesIO(pdf_file))
8
- text = ""
9
- for page in range(len(reader.pages)):
10
- text += reader.pages[page].extract_text()
11
- return text
12
 
13
- # ์ถ”์ถœ๋œ ํ…์ŠคํŠธ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์งˆ๋ฌธ์— ๋‹ต๋ณ€ํ•˜๋Š” ํ•จ์ˆ˜
14
- def answer_question(pdf_file, question):
15
- extracted_text = extract_text_from_pdf(pdf_file)
16
- if question in extracted_text:
17
- start = extracted_text.find(question)
18
- end = extracted_text.find('.', start) + 1
19
- return extracted_text[start:end]
20
- else:
21
- return "์งˆ๋ฌธ์— ๋Œ€ํ•œ ๋‹ต๋ณ€์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
22
 
23
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
24
  iface = gr.Interface(
25
- fn=answer_question,
26
- inputs=[gr.File(type="binary"), gr.Textbox(label="์งˆ๋ฌธ")],
27
- outputs=gr.Textbox()
28
  )
29
 
30
- # ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
31
  iface.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
 
3
 
4
+ # Hugging Face์˜ ํŠธ๋žœ์Šคํฌ๋จธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ด ๋ชจ๋ธ์„ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.
5
+ model = pipeline("text-classification", model="InstantX/InstantID")
 
 
 
 
 
6
 
7
+ # ๋ชจ๋ธ์„ ํ˜ธ์ถœํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
8
+ def predict(text):
9
+ return model(text)
 
 
 
 
 
 
10
 
11
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.
12
  iface = gr.Interface(
13
+ fn=predict,
14
+ inputs=gr.Textbox(lines=2, placeholder="Type something here..."),
15
+ outputs=[gr.Label(num_top_classes=3), gr.Dataframe()],
16
  )
17
 
18
+ # ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ํ…Œ์ŠคํŠธํ•ฉ๋‹ˆ๋‹ค.
19
  iface.launch()