-
-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
62 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import time | ||
|
||
import gevent | ||
from flask import Flask, request | ||
from gevent.pywsgi import WSGIServer | ||
from places365.places365 import Places365 | ||
|
||
app = Flask(__name__) | ||
|
||
places365_instance = None | ||
last_request_time = None | ||
|
||
|
||
def log(message): | ||
print("tags: {}".format(message)) | ||
|
||
|
||
@app.route("/generate-tags", methods=["POST"]) | ||
def generate_tags(): | ||
global last_request_time | ||
# Update last request time | ||
last_request_time = time.time() | ||
|
||
try: | ||
data = request.get_json() | ||
image_path = data["image_path"] | ||
confidence = data["confidence"] | ||
except Exception as e: | ||
print(str(e)) | ||
return "", 400 | ||
|
||
global places365_instance | ||
|
||
if places365_instance is None: | ||
places365_instance = Places365() | ||
return {"tags": places365_instance.inference_places365(image_path, confidence)}, 201 | ||
|
||
|
||
@app.route("/health", methods=["GET"]) | ||
def health(): | ||
return {"last_request_time": last_request_time}, 200 | ||
|
||
|
||
if __name__ == "__main__": | ||
log("service starting") | ||
server = WSGIServer(("0.0.0.0", 8011), app) | ||
server_thread = gevent.spawn(server.serve_forever) | ||
gevent.joinall([server_thread]) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters