Spaces:
Sleeping
Sleeping
File size: 1,089 Bytes
59c8923 7a07af2 1907678 59c8923 30ecb32 d5bc363 5e61ae1 30ecb32 59c8923 d5bc363 59c8923 d5bc363 59c8923 d5bc363 59c8923 d5bc363 e0cb5f0 da7e527 59c8923 2025471 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
from flask import Flask, request
from transformers import AutoModelForImageClassification
from transformers import AutoImageProcessor
from PIL import Image
from io import BytesIO
import os
import torch
app = Flask(__name__)
model = AutoModelForImageClassification.from_pretrained(
'./myModel')
image_processor = AutoImageProcessor.from_pretrained(
"google/vit-base-patch16-224-in21k")
@app.route('/upload_image', methods=['POST'])
def upload_image():
# Get the image file from the request
image_file = request.files['image'].stream
# image = Image.open(BytesIO(image_file.read()))
image = Image.open(image_file)
inputs = image_processor(image, return_tensors="pt")
with torch.no_grad():
logits = model(**inputs).logits
predicted_label = logits.argmax(-1).item()
disease = model.config.id2label[predicted_label]
# You can perform additional operations with the image here
# ...
return disease
@app.route('/', methods=['GET'])
def hi():
return "Hello world"
app.run(host='0.0.0.0', port=7860)
|