la04 commited on
Commit
f965a1f
·
verified ·
1 Parent(s): bb5fea8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -11,18 +11,14 @@ import os
11
  class LayoutLMv3OCR:
12
  def __init__(self):
13
  self.processor = LayoutLMv3Processor.from_pretrained("microsoft/layoutlmv3-base")
14
- # Ändere AutoModelForSeq2SeqLM zu AutoModelForTokenClassification
15
  self.model = AutoModelForTokenClassification.from_pretrained("microsoft/layoutlmv3-base")
16
 
17
  def extract_text(self, pdf_path):
18
  images = convert_from_path(pdf_path)
19
  text_pages = []
20
  for image in images:
21
- # Bilder werden für die OCR-Prozesse vorbereitet
22
  inputs = self.processor(images=image, return_tensors="pt")
23
- # Modell wird zur Textextraktion genutzt
24
  outputs = self.model(**inputs)
25
- # Hier wird der dekodierte Text extrahiert
26
  text = self.processor.batch_decode(outputs.logits, skip_special_tokens=True)[0]
27
  text_pages.append(text)
28
  return text_pages
@@ -52,9 +48,10 @@ def chatbot_response(pdf, question):
52
  os.remove(pdf_path)
53
  return answer
54
 
55
- pdf_input = gr.inputs.File(label="PDF-Datei hochladen")
56
- question_input = gr.inputs.Textbox(label="Frage eingeben")
57
- response_output = gr.outputs.Textbox(label="Antwort")
 
58
 
59
  interface = gr.Interface(
60
  fn=chatbot_response,
 
11
  class LayoutLMv3OCR:
12
  def __init__(self):
13
  self.processor = LayoutLMv3Processor.from_pretrained("microsoft/layoutlmv3-base")
 
14
  self.model = AutoModelForTokenClassification.from_pretrained("microsoft/layoutlmv3-base")
15
 
16
  def extract_text(self, pdf_path):
17
  images = convert_from_path(pdf_path)
18
  text_pages = []
19
  for image in images:
 
20
  inputs = self.processor(images=image, return_tensors="pt")
 
21
  outputs = self.model(**inputs)
 
22
  text = self.processor.batch_decode(outputs.logits, skip_special_tokens=True)[0]
23
  text_pages.append(text)
24
  return text_pages
 
48
  os.remove(pdf_path)
49
  return answer
50
 
51
+ # Ändere 'inputs' und 'outputs' zur neuen Gradio API
52
+ pdf_input = gr.File(label="PDF-Datei hochladen")
53
+ question_input = gr.Textbox(label="Frage eingeben")
54
+ response_output = gr.Textbox(label="Antwort")
55
 
56
  interface = gr.Interface(
57
  fn=chatbot_response,