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
import flask | |
from flask import Flask, request, jsonify | |
from PIL import Image | |
from flask_cors import CORS, cross_origin | |
from flask import send_file | |
app = flask.Flask(__name__) | |
app.config['CORS_HEADERS'] = 'Content-Type' | |
cors = CORS(app) | |
app.config["DEBUG"] = True | |
#Receive image | |
#Respond with return same image | |
@app.route('/sendimagetoserver',methods=['POST']) | |
def fetch_legging_recommendation(): | |
file = request.files['image'] | |
img = Image.open(file.stream) | |
source_file_name = 'Inputimage.jpg' | |
img = img.save(source_file_name) | |
return send_file(source_file_name, mimetype='image/jpg') | |
#For mac | |
#app.run(host= '0.0.0.0',port=4321,threaded=True) | |
#For windows | |
app.run(host= 'localhost',port=4321,threaded=True) |
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
import requests | |
def testmethod(): | |
url = 'http://127.0.0.1:4321/sendimagetoserver' | |
my_img = {'image': open(r'D1.jpg','rb')} | |
response = requests.post(url,files=my_img,timeout=20) | |
if response.status_code == 200: | |
with open("result_sample.jpg", 'wb') as f: | |
f.write(response.content) | |
print(response) | |
testmethod() |
More Read - Deploying a Flask app on AWS Lambda with Zappa
Keep Exploring!!!!
No comments:
Post a Comment