Spaces:
Running on Zero
Running on Zero
Commit ·
1308eeb
1
Parent(s): 1b70b38
[Admin maintenance] Support new ZeroGPU hardware (#16)
Browse files- [Admin maintenance] Support new ZeroGPU hardware (68b56b4fd34a2ef13150e65b04586cdc75ca7f65)
Files changed (3)
- app.py+8
- requirements.txt+15
- src/util.py+21-1
1 unmodified line234567200 unmodified lines2082092102112122131 unmodified line# -*- coding: utf-8 -*-# @Time : 2023-06-01# @Author : ashui(Binghui Chen)from sympy import imfrom versions import RELEASE_NOTE, VERSION200 unmodified lines)# user click the image to get points, and show the points on the imagedef segmentation(img, sel_pix):# online show seg maskpoints = []1 unmodified line234567891011121314200 unmodified lines2152162172182192202211 unmodified line# -*- coding: utf-8 -*-# @Time : 2023-06-01# @Author : ashui(Binghui Chen)# `spaces` MUST be imported before torch/cv2/anything that touches CUDA --# it monkeypatches torch.cuda so module-scope `.to("cuda")` calls below are# safely deferred instead of doing a real (and here, absent) CUDA init on the# CPU process. This app previously had no `import spaces` and no# `@spaces.GPU` decorator at all, so `mobile_sam = ...to("cuda")` a few lines# down triggered `RuntimeError: No CUDA GPUs are available`.import spacesfrom sympy import imfrom versions import RELEASE_NOTE, VERSION200 unmodified lines)# user click the image to get points, and show the points on the image@spaces.GPUdef segmentation(img, sel_pix):# online show seg maskpoints = []
1 unmodified line2345671 unmodified linesympyPillow==9.5.0gradio==3.50.2opencv-pythonomegaconfsentencepiece1 unmodified line23456789101112131415161718192021221 unmodified linesympyPillow==9.5.0gradio==3.50.2# gradio 3.50.2's routes.py calls Starlette's old# TemplateResponse(name, context) positional signature. Modern Starlette# (bundled with the current ZeroGPU base image) swapped to# TemplateResponse(request, name, context) -- under the old call convention# the dict `context` lands in the `name` slot, and Jinja2's template cache# then tries to hash that dict -> `TypeError: unhashable type: 'dict'` on# every request to "/". Pin an older, gradio-3.50.2-compatible Starlette/# FastAPI pair to match what this SDK version actually expects.starlette==0.27.0fastapi==0.104.1# fastapi 0.104.1 uses pydantic's old FieldInfo API (field_info.in_); the base# image otherwise installs pydantic 2.13.x which removed it -> at Blocks()# construction: AttributeError: 'FieldInfo' object has no attribute 'in_'.# Pin pydantic to the release fastapi 0.104.1 / gradio 3.50.2 were built against.pydantic==2.4.2opencv-pythonomegaconfsentencepiece
22 unmodified lines2324252627282925 unmodified lines55565758596022 unmodified linesbucket_name = os.getenv("BUCKET_NAME")endpoint = os.getenv("ENDPOINT")bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name)oss_path = "ashui"oss_path_img_gallery = "ashui_img_gallery"25 unmodified linesreturn imgs_pildef upload_np_2_oss(input_image, name="cache.png", gallery=False):imgByteArr = io.BytesIO()Image.fromarray(input_image).save(imgByteArr, format="PNG")imgByteArr = imgByteArr.getvalue()22 unmodified lines2324252627282930313233343536373839404142434425 unmodified lines707172737475767778798022 unmodified linesbucket_name = os.getenv("BUCKET_NAME")endpoint = os.getenv("ENDPOINT")# The original Space depends on a private Alibaba Cloud OSS bucket# (ACCESS_KEY_ID / ACCESS_KEY_SECRET / BUCKET_NAME / ENDPOINT secrets) that# isn't available here. Without this guard, `oss2.Bucket(...)` raises# AttributeError: 'NoneType' object has no attribute 'strip' at import time,# crashing the whole app before it ever reaches the (unrelated) CUDA bug this# duplicate is meant to repro. Degrade to `bucket = None` instead so import# succeeds; only the OSS-upload path (unreachable without those secrets)# fails at call time with a clear error.if access_key_id and access_key_secret and bucket_name and endpoint:bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name)else:logger.error("OSS credentials (ACCESS_KEY_ID/ACCESS_KEY_SECRET/BUCKET_NAME/ENDPOINT) ""are not set; image-upload features will be disabled.")bucket = Noneoss_path = "ashui"oss_path_img_gallery = "ashui_img_gallery"25 unmodified linesreturn imgs_pildef upload_np_2_oss(input_image, name="cache.png", gallery=False):if bucket is None:raise RuntimeError("OSS bucket is not configured (missing ACCESS_KEY_ID/ACCESS_KEY_SECRET/""BUCKET_NAME/ENDPOINT secrets); cannot upload images.")imgByteArr = io.BytesIO()Image.fromarray(input_image).save(imgByteArr, format="PNG")imgByteArr = imgByteArr.getvalue()
app.py+8
requirements.txt+15
src/util.py+21-1