Spaces:
Running on Zero
Running on Zero
Add agent skill download endpoint
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from pathlib import Path
|
|
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
|
|
@@ -207,6 +208,13 @@ structured_json_templates = {
|
|
| 207 |
|
| 208 |
default_structured_json_template = "Invoice with line items"
|
| 209 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
with gr.Blocks(title="Image Data Extractor") as demo:
|
| 212 |
gr.Markdown(
|
|
@@ -214,6 +222,15 @@ with gr.Blocks(title="Image Data Extractor") as demo:
|
|
| 214 |
"Extract structured JSON from an image and optional text using "
|
| 215 |
"[numind/NuExtract3](https://huggingface.co/numind/NuExtract3)."
|
| 216 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
with gr.Row():
|
| 218 |
with gr.Column():
|
| 219 |
image = gr.Image(label="Document image", type="pil", height=430)
|
|
@@ -230,7 +247,9 @@ with gr.Blocks(title="Image Data Extractor") as demo:
|
|
| 230 |
info="Choose a starting structure, then edit it below.",
|
| 231 |
)
|
| 232 |
generate_template_button = gr.Button("Generate template from Image")
|
| 233 |
-
with gr.Accordion(
|
|
|
|
|
|
|
| 234 |
template = gr.Textbox(
|
| 235 |
label="Structured JSON template",
|
| 236 |
value=structured_json_templates[default_structured_json_template],
|
|
@@ -318,7 +337,18 @@ with gr.Blocks(title="Image Data Extractor") as demo:
|
|
| 318 |
api_name="select_structured_json_template",
|
| 319 |
)
|
| 320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
generate_template_button.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
generate_template,
|
| 323 |
inputs=image,
|
| 324 |
outputs=template,
|
|
|
|
| 1 |
from pathlib import Path
|
| 2 |
+
import shutil
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
|
|
|
|
| 208 |
|
| 209 |
default_structured_json_template = "Invoice with line items"
|
| 210 |
|
| 211 |
+
def download_agentskill():
|
| 212 |
+
return shutil.make_archive(
|
| 213 |
+
"extract-image-data",
|
| 214 |
+
"zip",
|
| 215 |
+
root_dir=".agents/skills",
|
| 216 |
+
base_dir="extract-image-data",
|
| 217 |
+
)
|
| 218 |
|
| 219 |
with gr.Blocks(title="Image Data Extractor") as demo:
|
| 220 |
gr.Markdown(
|
|
|
|
| 222 |
"Extract structured JSON from an image and optional text using "
|
| 223 |
"[numind/NuExtract3](https://huggingface.co/numind/NuExtract3)."
|
| 224 |
)
|
| 225 |
+
gr.Markdown(
|
| 226 |
+
"## Install the agent skill\n"
|
| 227 |
+
"Download the ZIP, extract it, and place the `extract-image-data` folder "
|
| 228 |
+
"in your project's `.agents/skills/` directory. Agents should read its "
|
| 229 |
+
"`SKILL.md` and use it whenever a task requires structured extraction "
|
| 230 |
+
"from an image."
|
| 231 |
+
)
|
| 232 |
+
download_agentskill_button = gr.Button("Download agent skill")
|
| 233 |
+
download_agentskill_file = gr.File(label="Agent skill ZIP")
|
| 234 |
with gr.Row():
|
| 235 |
with gr.Column():
|
| 236 |
image = gr.Image(label="Document image", type="pil", height=430)
|
|
|
|
| 247 |
info="Choose a starting structure, then edit it below.",
|
| 248 |
)
|
| 249 |
generate_template_button = gr.Button("Generate template from Image")
|
| 250 |
+
with gr.Accordion(
|
| 251 |
+
"Structured JSON template", open=False
|
| 252 |
+
) as template_accordion:
|
| 253 |
template = gr.Textbox(
|
| 254 |
label="Structured JSON template",
|
| 255 |
value=structured_json_templates[default_structured_json_template],
|
|
|
|
| 337 |
api_name="select_structured_json_template",
|
| 338 |
)
|
| 339 |
|
| 340 |
+
download_agentskill_button.click(
|
| 341 |
+
download_agentskill,
|
| 342 |
+
outputs=download_agentskill_file,
|
| 343 |
+
api_name="download_agentskill",
|
| 344 |
+
)
|
| 345 |
+
|
| 346 |
generate_template_button.click(
|
| 347 |
+
lambda: gr.Accordion(open=True),
|
| 348 |
+
outputs=template_accordion,
|
| 349 |
+
api_visibility="private",
|
| 350 |
+
show_progress="hidden",
|
| 351 |
+
).then(
|
| 352 |
generate_template,
|
| 353 |
inputs=image,
|
| 354 |
outputs=template,
|