Spaces:
Runtime error
Runtime error
Gaurav
commited on
Commit
•
55e9f56
1
Parent(s):
cea324f
Upload 2 files
Browse files- app.py +36 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import json
|
3 |
+
from flask import Flask
|
4 |
+
from flask import request
|
5 |
+
import base64
|
6 |
+
import io
|
7 |
+
|
8 |
+
app = Flask(__name__)
|
9 |
+
|
10 |
+
|
11 |
+
detector = pipeline("zero-shot-object-detection", model="google/owlvit-base-patch32",device=-1,framework="pt")
|
12 |
+
#depth_estimator = pipeline("depth-estimation", model="Intel/dpt-large")
|
13 |
+
|
14 |
+
|
15 |
+
def process(image, items):
|
16 |
+
preds = detector("https://visualization.graberblinds.com/assets/sample_sessions/02e1d080-c4bf-4cdc-b1bc-f39f9b2a2230_thumb.jpg", candidate_labels=items)
|
17 |
+
return preds
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
@app.route("/",methods=["POST"])
|
22 |
+
def detect():
|
23 |
+
|
24 |
+
from PIL import Image
|
25 |
+
body=request.get_json()
|
26 |
+
base64_str=body['img']
|
27 |
+
# Assuming base64_str is the string value without 'data:image/jpeg;base64,'
|
28 |
+
img = Image.open(io.BytesIO(base64.decodebytes(bytes(base64_str, "utf-8"))))
|
29 |
+
items ="window"
|
30 |
+
preds=process(img,items)
|
31 |
+
response=app.make_response(json.dumps(preds))
|
32 |
+
response.content_type="application/json"
|
33 |
+
return response
|
34 |
+
|
35 |
+
|
36 |
+
app.run(debug=True,port="7860")
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch==2.0.1
|
2 |
+
Pillow==9.5.0
|
3 |
+
transformers==4.29.2
|
4 |
+
Flask==2.0.3
|