tasbot/interrogator/app.py
2023-03-07 16:46:32 +01:00

27 lines
677 B
Python

from flask import Flask, request
app = Flask(__name__)
from PIL import Image
from clip_interrogator import Config, Interrogator
ci = Interrogator(Config(clip_model_name="ViT-L-14/openai"))
#ci = Interrogator(Config(clip_model_name="ViT-H-14/laion2b_s32b_b79k"))
image_path = "/dev/shm/image_data"
import requests
@app.route("/", methods=['GET'])
def hello_world():
args = request.args
img_data = requests.get(args['image_url']).content
with open(image_path, 'wb') as handler:
handler.write(img_data)
image = Image.open(image_path).convert('RGB')
#return {'message': ci.interrogate(image)}
return {'message': ci.interrogate_fast(image)}