Spaces:
Sleeping
Sleeping
[Admin maintenance] Support new ZeroGPU hardware
#3
by multimodalart HF Staff - opened
- README.md +1 -1
- app.py +21 -2
- requirements.txt +0 -1
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 🏃
|
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
|
|
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.50.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
app.py
CHANGED
|
@@ -1,14 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import torch
|
| 4 |
from PIL import Image
|
| 5 |
from gradio_image_prompter import ImagePrompter
|
|
|
|
|
|
|
| 6 |
from transformers import AutoProcessor, UdopForConditionalGeneration
|
| 7 |
import easyocr
|
| 8 |
from PIL import Image
|
| 9 |
-
import spaces
|
| 10 |
from typing import Optional, List, TypedDict, Union, Literal
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
class PromptValue(TypedDict):
|
| 14 |
image: Optional[Union[Image.Image, str]]
|
|
@@ -42,7 +61,7 @@ def udop_box_inference(image, text_prompt, box_coordinates):
|
|
| 42 |
for box in bboxs:
|
| 43 |
norm_boxes.append(normalize_bbox(box, width, height))
|
| 44 |
|
| 45 |
-
encoding = processor(image, text_prompt, texts, boxes=norm_boxes, return_tensors="pt")
|
| 46 |
predicted_ids = model.generate(**encoding)
|
| 47 |
return processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
|
| 48 |
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
+
import subprocess
|
| 3 |
+
subprocess.run(["pip", "install", "--no-deps", "gradio-image-prompter"])
|
| 4 |
+
|
| 5 |
import gradio as gr
|
| 6 |
import numpy as np
|
| 7 |
import torch
|
| 8 |
from PIL import Image
|
| 9 |
from gradio_image_prompter import ImagePrompter
|
| 10 |
+
import gradio_image_prompter.image_prompter as _ip
|
| 11 |
+
from gradio.data_classes import FileData
|
| 12 |
from transformers import AutoProcessor, UdopForConditionalGeneration
|
| 13 |
import easyocr
|
| 14 |
from PIL import Image
|
|
|
|
| 15 |
from typing import Optional, List, TypedDict, Union, Literal
|
| 16 |
|
| 17 |
+
# gradio_image_prompter 0.1.0 was built for gradio 4.x; under gradio 5 its
|
| 18 |
+
# postprocess returns an ImageData that no longer subclasses FileData, so the
|
| 19 |
+
# PromptData model raises a pydantic ValidationError. Convert it back.
|
| 20 |
+
_orig_img_post = gr.Image.postprocess
|
| 21 |
+
def _patched_ip_postprocess(self, y):
|
| 22 |
+
if y is None:
|
| 23 |
+
return None
|
| 24 |
+
image, points = y.get("image", None), y.get("points", [])
|
| 25 |
+
img = _orig_img_post(self, image)
|
| 26 |
+
if img is not None and not isinstance(img, FileData):
|
| 27 |
+
img = FileData(**img.model_dump())
|
| 28 |
+
return _ip.PromptData(image=img, points=points)
|
| 29 |
+
ImagePrompter.postprocess = _patched_ip_postprocess
|
| 30 |
+
|
| 31 |
|
| 32 |
class PromptValue(TypedDict):
|
| 33 |
image: Optional[Union[Image.Image, str]]
|
|
|
|
| 61 |
for box in bboxs:
|
| 62 |
norm_boxes.append(normalize_bbox(box, width, height))
|
| 63 |
|
| 64 |
+
encoding = processor(image, text_prompt, text_pair=texts, boxes=norm_boxes, return_tensors="pt")
|
| 65 |
predicted_ids = model.generate(**encoding)
|
| 66 |
return processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
|
| 67 |
|
requirements.txt
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
git+https://github.com/huggingface/transformers.git
|
| 2 |
-
gradio-image-prompter
|
| 3 |
easyocr
|
| 4 |
spaces
|
| 5 |
torch
|
|
|
|
| 1 |
git+https://github.com/huggingface/transformers.git
|
|
|
|
| 2 |
easyocr
|
| 3 |
spaces
|
| 4 |
torch
|