Spaces:
Sleeping
Sleeping
Create a0p.py
Browse files
a0p.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
from transformers import pipeline
|
3 |
+
from PIL import Image
|
4 |
+
import requests
|
5 |
+
import logging
|
6 |
+
import torch
|
7 |
+
from transformers import pipeline
|
8 |
+
|
9 |
+
print("Loading model...")
|
10 |
+
|
11 |
+
#torch.backends.cuda.matmul.allow_tf32 = True
|
12 |
+
#torch.backends.cudnn.allow_tf32 = True
|
13 |
+
|
14 |
+
pipe = pipeline("image-classification", model="./checkpoint-600")
|
15 |
+
|
16 |
+
print("Starting webapp...")
|
17 |
+
|
18 |
+
app = Flask(__name__)
|
19 |
+
log = logging.getLogger('werkzeug')
|
20 |
+
log.disabled = True
|
21 |
+
app.logger.disabled = True
|
22 |
+
|
23 |
+
print("Ready")
|
24 |
+
|
25 |
+
@app.route("/")
|
26 |
+
def classify_image():
|
27 |
+
global pipe
|
28 |
+
|
29 |
+
if url is None:
|
30 |
+
return jsonify(error="Url is required", url=None, label=None)
|
31 |
+
|
32 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
33 |
+
|
34 |
+
output = pipe(images=[image])
|
35 |
+
|
36 |
+
return jsonify(url=url, result=output)
|