Instantnewdesign commited on
Commit
489af81
·
verified ·
1 Parent(s): ebfb2f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -35
app.py CHANGED
@@ -1,42 +1,26 @@
1
  import gradio as gr
2
- from PIL import Image
3
- from mineru_vl_utils import MinerUClient
4
- from transformers import AutoProcessor, Qwen2VLForConditionalGeneration
5
 
6
- # Charger le modèle MinerU
7
- model_path = "opendatalab/MinerU2.5-2509-1.2B"
8
- model = Qwen2VLForConditionalGeneration.from_pretrained(
9
- model_path,
10
- torch_dtype="auto",
11
- device_map="auto"
12
- )
13
- processor = AutoProcessor.from_pretrained(model_path, use_fast=True)
14
 
15
- client = MinerUClient(
16
- backend="transformers",
17
- model=model,
18
- processor=processor
19
- )
 
 
 
20
 
21
- def extract_from_image(image):
22
- # Conversion si nécessaire
23
- if not isinstance(image, Image.Image):
24
- image = Image.fromarray(image)
25
 
26
- # Extraction
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()