bharatcoder commited on
Commit
989a4f7
·
verified ·
1 Parent(s): 4d88a04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -6
app.py CHANGED
@@ -69,14 +69,37 @@ def smoldocling_readimage(image: Image.Image, prompt_text: str) -> str:
69
  # -----------------------------
70
  # Wrapper for MCP schema compatibility
71
  # -----------------------------
72
- def smoldocling_entry(image: object, prompt_text: str) -> str:
73
  """
74
- Entry point for MCP tool.
75
- Accepts any of:
76
- - base64 string
77
- - dict {"type": "image", "data": "data:image/png;base64,..."}
78
- - file path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  """
 
 
 
 
 
 
 
 
 
80
  pil_image = convert_to_pil(image)
81
  return smoldocling_readimage(pil_image, prompt_text)
82
 
 
69
  # -----------------------------
70
  # Wrapper for MCP schema compatibility
71
  # -----------------------------
72
+ def smoldocling_entry(image: str, prompt_text: str) -> str:
73
  """
74
+ Entry point for the SmolDocling MCP tool.
75
+
76
+ Expected input formats:
77
+ - **Base64 string**: "data:image/png;base64,...."
78
+ - **Object** (Perplexity/Claude style): {"type": "image", "data": "data:image/png;base64,..."}
79
+ - **Local file path** (for internal testing)
80
+
81
+ Parameters
82
+ ----------
83
+ image : str
84
+ A base64-encoded image string (with or without data: prefix) OR
85
+ a JSON-encoded object containing image data.
86
+ prompt_text : str
87
+ Instruction text for how to process the document (e.g., "Convert this page to docling.")
88
+
89
+ Returns
90
+ -------
91
+ str
92
+ Structured or textual content extracted from the image.
93
  """
94
+ # Handle Perplexity-style dicts encoded as JSON strings
95
+ try:
96
+ import json
97
+ maybe_json = json.loads(image)
98
+ if isinstance(maybe_json, dict) and "data" in maybe_json:
99
+ image = maybe_json
100
+ except Exception:
101
+ pass
102
+
103
  pil_image = convert_to_pil(image)
104
  return smoldocling_readimage(pil_image, prompt_text)
105