Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,28 @@
|
|
| 1 |
-
from
|
| 2 |
-
text= pipeline("image-to-text")
|
| 3 |
-
|
| 4 |
import gradio as gr
|
|
|
|
| 5 |
from PIL import Image
|
| 6 |
-
import pytesseract
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
return text
|
| 12 |
|
| 13 |
-
# Interface Gradio
|
| 14 |
-
inputs = gr.Image(label="Sélectionnez une image")
|
| 15 |
-
outputs = gr.Textbox(label="Texte extrait")
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
fn=image_to_text,
|
| 19 |
-
inputs=
|
| 20 |
-
outputs=
|
| 21 |
-
title="Image vers Texte",
|
| 22 |
description="Téléchargez une image et cliquez sur 'Soumettre' pour extraire le texte.",
|
| 23 |
)
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
| 1 |
+
from pickle import APPEND
|
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
+
from transformers import LayoutLMForTokenClassification, LayoutLMTokenizer
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
|
| 6 |
+
model_name = "microsoft/layoutlm-base-uncased"
|
| 7 |
+
tokenizer = LayoutLMTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = LayoutLMForTokenClassification.from_pretrained(model_name)
|
|
|
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
def image_to_text(image):
|
| 12 |
+
image = Image.open(image.name)
|
| 13 |
+
inputs = tokenizer(image, return_tensors="pt", padding=True, truncation=True)
|
| 14 |
+
outputs = model(**inputs)
|
| 15 |
+
predicted_ids = outputs.logits.argmax(-1)
|
| 16 |
+
predicted_text = tokenizer.decode(predicted_ids[0])
|
| 17 |
+
return predicted_text
|
| 18 |
+
|
| 19 |
+
app= gr.Interface(
|
| 20 |
fn=image_to_text,
|
| 21 |
+
inputs=gr.Image(label="Sélectionnez une image"),
|
| 22 |
+
outputs=gr.Textbox(label="Texte extrait"),
|
| 23 |
+
title="Image vers Texte ",
|
| 24 |
description="Téléchargez une image et cliquez sur 'Soumettre' pour extraire le texte.",
|
| 25 |
)
|
| 26 |
|
| 27 |
+
|
| 28 |
+
app.launch()
|