Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
from transformers import AutoProcessor, Qwen2VLForConditionalGeneration
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
device_map="auto"
|
| 12 |
-
)
|
| 13 |
-
processor = AutoProcessor.from_pretrained(model_path, use_fast=True)
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
)
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
def
|
| 22 |
-
|
| 23 |
-
if not isinstance(image, Image.Image):
|
| 24 |
-
image = Image.fromarray(image)
|
| 25 |
|
| 26 |
-
|
| 27 |
-
blocks = client.two_step_extract(image)
|
| 28 |
-
# On retourne le texte concaténé
|
| 29 |
-
extracted_text = "\n".join([b.text for b in blocks if hasattr(b, "text")])
|
| 30 |
-
return extracted_text
|
| 31 |
-
|
| 32 |
-
# Interface Gradio
|
| 33 |
-
demo = gr.Interface(
|
| 34 |
-
fn=extract_from_image,
|
| 35 |
-
inputs=gr.Image(type="pil"),
|
| 36 |
-
outputs="text",
|
| 37 |
-
title="MinerU2.5 - Document Extract",
|
| 38 |
-
description="Upload an image or PDF page and extract structured text with MinerU2.5"
|
| 39 |
-
)
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
| 42 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import logging
|
| 3 |
+
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
| 4 |
|
| 5 |
+
try:
|
| 6 |
+
from mineru_vl_utils import MinerUClient
|
| 7 |
+
print("✅ mineru-vl-utils importé")
|
| 8 |
+
except Exception as e:
|
| 9 |
+
print("❌ Erreur import mineru-vl-utils:", e)
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
try:
|
| 12 |
+
client = MinerUClient(
|
| 13 |
+
backend="transformers",
|
| 14 |
+
model_path="opendatalab/MinerU2.5-2509-1.2B"
|
| 15 |
+
)
|
| 16 |
+
print("✅ Client MinerU initialisé")
|
| 17 |
+
except Exception as e:
|
| 18 |
+
print("❌ Erreur init MinerUClient:", e)
|
| 19 |
|
| 20 |
+
def test_fn():
|
| 21 |
+
return "Space lancé avec succès ✅"
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
demo = gr.Interface(fn=test_fn, inputs=[], outputs="text")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
| 26 |
+
demo.launch()
|