Spaces:
Runtime error
Runtime error
from transformers import pipeline | |
import json | |
from flask import Flask | |
from flask import request | |
import base64 | |
import io | |
import os | |
os.environ['SENTENCE_TRANSFORMERS_HOME'] = '/code/.cache' | |
os.environ['TRANSFORMERS_CACHE '] = '/code/.cache' | |
app = Flask(__name__) | |
detector = pipeline("zero-shot-object-detection", model="google/owlvit-base-patch32",device=-1,framework="pt") | |
#depth_estimator = pipeline("depth-estimation", model="Intel/dpt-large") | |
def process(image, items): | |
preds = detector("https://visualization.graberblinds.com/assets/sample_sessions/02e1d080-c4bf-4cdc-b1bc-f39f9b2a2230_thumb.jpg", candidate_labels=items) | |
return preds | |
def detect(): | |
from PIL import Image | |
body=request.get_json() | |
base64_str=body['img'] | |
# Assuming base64_str is the string value without 'data:image/jpeg;base64,' | |
img = Image.open(io.BytesIO(base64.decodebytes(bytes(base64_str, "utf-8")))) | |
items ="window" | |
preds=process(img,items) | |
response=app.make_response(json.dumps(preds)) | |
response.content_type="application/json" | |
return response | |
app.run(debug=True,port="7860") |