SnowFlash383935 commited on
Commit
e376229
·
verified ·
1 Parent(s): 667e0f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -1,22 +1,22 @@
 
1
  import gradio as gr
2
- import easyocr
3
 
4
- reader = easyocr.Reader(['ru', 'en'])
 
5
 
6
- def recognize_text(image):
7
- results = reader.readtext(image)
8
- output = [(text, f"{round(prob*100, 2)}%") for (bbox, text, prob) in results]
9
- return output
10
 
11
- interface = gr.Interface(
12
- fn=recognize_text,
13
- inputs=gr.Image(type="filepath", label="📷 Загрузите изображение бланка"),
14
- outputs=gr.HighlightedText(label="🔍 Распознанный текст", combine_adjacent=True),
15
- title="🦁 OCRion",
16
- description="Распознавание текста на бланках с помощью EasyOCR. Подходит даже для \"свиного\" почерка!",
17
- examples=[["example.png"]], # Можно добавить пример
18
- )
19
-
20
- if __name__ == "__main__":
21
- interface.launch(ssr_mode=False, share=True)
22
-
 
1
+ from transformers import pipeline
2
  import gradio as gr
3
+ from PIL import Image
4
 
5
+ # Загружаем модель
6
+ pipe = pipeline(model="impira/layoutlm-document-qa")
7
 
8
+ def ask_document(image, question):
9
+ result = pipe(image=image, question=question)
10
+ return result
 
11
 
12
+ # Интерфейс
13
+ gr.Interface(
14
+ fn=ask_document,
15
+ inputs=[
16
+ gr.Image(type="pil", label="📷 Загрузите бланк"),
17
+ gr.Textbox(label=" Вопрос", placeholder="Например: Какая фамилия?")
18
+ ],
19
+ outputs=gr.JSON(label="🧠 Ответ"),
20
+ title="🦁 OCRion v2 (Document QA)",
21
+ description="Задайте вопрос о содержимом бланка — нейросеть сама найдёт ответ!"
22
+ ).launch()