electblake commited on
Commit
3f76dfa
·
verified ·
1 Parent(s): 2ab3f5a

Add downloadable image extraction skill

Browse files
.agents/skills/extract-image-data/SKILL.md ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: extract-image-data
3
+ description: Extract structured data from document images through the electblake/image-data-extractor Gradio Space API. Use when calling its template selection, template generation, or image extraction endpoints from Python, JavaScript, or cURL.
4
+ ---
5
+
6
+ # Extract Image Data (API)
7
+
8
+ This skill describes how to use the electblake/image-data-extractor Gradio Space programmatically.
9
+
10
+ ## API Endpoints
11
+
12
+ ### `/select_structured_json_template`
13
+
14
+ **Parameters:**
15
+
16
+ - `key` [Dropdown]: `Literal['Basic receipt', 'Advanced receipt', 'Basic bank statement', 'Advanced bank statement', 'Invoice with line items', 'Advanced global record']`, default: `Invoice with line items`
17
+
18
+ **Returns:**
19
+
20
+ - `Structured JSON template` [Textbox]: `str`
21
+
22
+ **Python:**
23
+
24
+ ```python
25
+ from gradio_client import Client
26
+
27
+ client = Client("electblake/image-data-extractor")
28
+ result = client.predict(
29
+ key="Invoice with line items",
30
+ api_name="/select_structured_json_template",
31
+ )
32
+ print(result)
33
+ ```
34
+
35
+ **JavaScript:**
36
+
37
+ ```javascript
38
+ import { Client } from "@gradio/client";
39
+
40
+ const client = await Client.connect("electblake/image-data-extractor");
41
+ const result = await client.predict("/select_structured_json_template", {
42
+ key: "Invoice with line items",
43
+ });
44
+
45
+ console.log(result.data);
46
+ ```
47
+
48
+ **cURL:**
49
+
50
+ ```bash
51
+ curl -X POST https://electblake-image-data-extractor.hf.space/call/v2/select_structured_json_template -s -H "Content-Type: application/json" \
52
+ -d '{"key": "Invoice with line items"}' \
53
+ | awk -F'"' '{ print $4}' \
54
+ | read EVENT_ID; curl -N https://electblake-image-data-extractor.hf.space/call/select_structured_json_template/$EVENT_ID
55
+ ```
56
+
57
+ ### `/generate_template`
58
+
59
+ **Parameters:**
60
+
61
+ - `image` [Image]: `filepath` (required)
62
+
63
+ **Returns:**
64
+
65
+ - `Structured JSON template` [Textbox]: `str`
66
+
67
+ **Python:**
68
+
69
+ ```python
70
+ from gradio_client import Client, handle_file
71
+
72
+ client = Client("electblake/image-data-extractor")
73
+ result = client.predict(
74
+ image=handle_file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
75
+ api_name="/generate_template",
76
+ )
77
+ print(result)
78
+ ```
79
+
80
+ **JavaScript:**
81
+
82
+ ```javascript
83
+ import { Client } from "@gradio/client";
84
+
85
+ const response_0 = await fetch("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png");
86
+ const exampleImage = await response_0.blob();
87
+
88
+ const client = await Client.connect("electblake/image-data-extractor");
89
+ const result = await client.predict("/generate_template", {
90
+ image: exampleImage,
91
+ });
92
+
93
+ console.log(result.data);
94
+ ```
95
+
96
+ **cURL:**
97
+
98
+ ```bash
99
+ FILE_PATH=$(curl -s -X POST https://electblake-image-data-extractor.hf.space/upload -F 'files=@/path/to/your/file' | tr -d '[]" ')
100
+
101
+ curl -X POST https://electblake-image-data-extractor.hf.space/call/v2/generate_template -s -H "Content-Type: application/json" \
102
+ -d '{"image": {"path": "'$FILE_PATH'", "meta": {"_type": "gradio.FileData"}}}' \
103
+ | awk -F'"' '{ print $4}' \
104
+ | read EVENT_ID; curl -N https://electblake-image-data-extractor.hf.space/call/generate_template/$EVENT_ID
105
+ ```
106
+
107
+ ### `/extract`
108
+
109
+ **Parameters:**
110
+
111
+ - `image` [Image]: `filepath` (required)
112
+ - `text` [Textbox]: `str` (required)
113
+ - `template` [Textbox]: `str`, default: `{
114
+ "document_type": "verbatim-string",
115
+ "vendor": {
116
+ "name": "verbatim-string",
117
+ "address": "verbatim-string",
118
+ "email": "email-address",
119
+ "phone": "phone-number"
120
+ },
121
+ "invoice_number": "verbatim-string",
122
+ "invoice_date": "verbatim-string",
123
+ "line_items": [
124
+ {
125
+ "description": "verbatim-string",
126
+ "category": ["product", "service", "shipping", "tax", "other"],
127
+ "quantity": "integer",
128
+ "unit_price": "number",
129
+ "unit": "unit-code",
130
+ "amount": "number"
131
+ }
132
+ ],
133
+ "subtotal": "number",
134
+ "tax": "number",
135
+ "total": "number",
136
+ "currency": "currency"
137
+ }`
138
+ - `enable_thinking` [Checkbox]: `bool`, default: `False`
139
+
140
+ **Returns:**
141
+
142
+ - `Structured JSON` [Json]: `str | float | bool | list | dict`
143
+
144
+ **Python:**
145
+
146
+ ```python
147
+ from gradio_client import Client, handle_file
148
+
149
+ client = Client("electblake/image-data-extractor")
150
+ result = client.predict(
151
+ image=handle_file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
152
+ text="Hello!!",
153
+ template="{
154
+ "document_type": "verbatim-string",
155
+ "vendor": {
156
+ "name": "verbatim-string",
157
+ "address": "verbatim-string",
158
+ "email": "email-address",
159
+ "phone": "phone-number"
160
+ },
161
+ "invoice_number": "verbatim-string",
162
+ "invoice_date": "verbatim-string",
163
+ "line_items": [
164
+ {
165
+ "description": "verbatim-string",
166
+ "category": ["product", "service", "shipping", "tax", "other"],
167
+ "quantity": "integer",
168
+ "unit_price": "number",
169
+ "unit": "unit-code",
170
+ "amount": "number"
171
+ }
172
+ ],
173
+ "subtotal": "number",
174
+ "tax": "number",
175
+ "total": "number",
176
+ "currency": "currency"
177
+ }",
178
+ enable_thinking=False,
179
+ api_name="/extract",
180
+ )
181
+ print(result)
182
+ ```
183
+
184
+ **JavaScript:**
185
+
186
+ ```javascript
187
+ import { Client } from "@gradio/client";
188
+
189
+ const response_0 = await fetch("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png");
190
+ const exampleImage = await response_0.blob();
191
+
192
+ const client = await Client.connect("electblake/image-data-extractor");
193
+ const result = await client.predict("/extract", {
194
+ image: exampleImage,
195
+ text: "Hello!!",
196
+ template: "{
197
+ "document_type": "verbatim-string",
198
+ "vendor": {
199
+ "name": "verbatim-string",
200
+ "address": "verbatim-string",
201
+ "email": "email-address",
202
+ "phone": "phone-number"
203
+ },
204
+ "invoice_number": "verbatim-string",
205
+ "invoice_date": "verbatim-string",
206
+ "line_items": [
207
+ {
208
+ "description": "verbatim-string",
209
+ "category": ["product", "service", "shipping", "tax", "other"],
210
+ "quantity": "integer",
211
+ "unit_price": "number",
212
+ "unit": "unit-code",
213
+ "amount": "number"
214
+ }
215
+ ],
216
+ "subtotal": "number",
217
+ "tax": "number",
218
+ "total": "number",
219
+ "currency": "currency"
220
+ }",
221
+ enable_thinking: false,
222
+ });
223
+
224
+ console.log(result.data);
225
+ ```
226
+
227
+ **cURL:**
228
+
229
+ ```bash
230
+ FILE_PATH=$(curl -s -X POST https://electblake-image-data-extractor.hf.space/upload -F 'files=@/path/to/your/file' | tr -d '[]" ')
231
+
232
+ curl -X POST https://electblake-image-data-extractor.hf.space/call/v2/extract -s -H "Content-Type: application/json" \
233
+ -d '{"image": {"path": "'$FILE_PATH'", "meta": {"_type": "gradio.FileData"}}, "text": "Hello!!", "template": "{
234
+ "document_type": "verbatim-string",
235
+ "vendor": {
236
+ "name": "verbatim-string",
237
+ "address": "verbatim-string",
238
+ "email": "email-address",
239
+ "phone": "phone-number"
240
+ },
241
+ "invoice_number": "verbatim-string",
242
+ "invoice_date": "verbatim-string",
243
+ "line_items": [
244
+ {
245
+ "description": "verbatim-string",
246
+ "category": ["product", "service", "shipping", "tax", "other"],
247
+ "quantity": "integer",
248
+ "unit_price": "number",
249
+ "unit": "unit-code",
250
+ "amount": "number"
251
+ }
252
+ ],
253
+ "subtotal": "number",
254
+ "tax": "number",
255
+ "total": "number",
256
+ "currency": "currency"
257
+ }", "enable_thinking": false}' \
258
+ | awk -F'"' '{ print $4}' \
259
+ | read EVENT_ID; curl -N https://electblake-image-data-extractor.hf.space/call/extract/$EVENT_ID
260
+ ```
261
+
.agents/skills/extract-image-data/agents/openai.yaml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ interface:
2
+ display_name: "Extract Image Data (API)"
3
+ short_description: "Extract structured data from document images"
4
+ default_prompt: "Use $extract-image-data to extract structured data from a document image through the API."