Rest Api using python with image as parameter - python

I am trying to build a REST API in which a user can send an image and another variable as parameters and in return the image function returns the image as response.
Right now I have built a file upload and I processes the uploaded file and it is saved to a location that is given as download link. But I want to make it accessible for other programmers so they can also use the feature and include it in their programs
http://Imageprocessr.com/ProcessImage/img="imagefile**"&&para="val"
So how to send an image as a parameter and return the image using response just like how we can return other data like texts etc.

Related

Botbuilder Update Image Flask

I am using Flask to build an Azure bot with botbuilder library, and I use a local image in a herocard. However, when I go to my source code and change the content of this local image or even delete this local image, the bot still sends a herocard with the old image. Why it happen and how to fix it because I need to change the content of the png file for a user input?

How to get GCP Function generated image to be recognized as valid in GC Storage?

I am trying to create an image thumbnail creation function using python, running in a google cloud platform's function. The image is sent as a base64 string to the cloud function, manipulated and made smaller with Python's Pillow package. It is then uploaded as an image, going from a Pillow Image object, to a BytesIO object, then saved to google cloud storage. This is all done successfully.
The problem here is very strange: Google Cloud Storage does not recognize the image until an access token is created manually. Otherwise, the image is left in an infinite loop, never loading, and never being able to be used.
I have reviewed this SO post, which has a very similar problem to mine (the image here shows exactly my problem: an uploaded file cannot be loaded properly), but it differs in two imporant categories: 1) They are manipulating the image array directly, while my code never touches it and 2) they are working in Node.js, where the Firebase SDK is different than in Python.
The code to generate the image is as follows:
def thumbnailCreator(request):
# Setting up the resourcse we are going to use
storage_client = storage.Client()
stor_bucket = storage_client.bucket(BUCKET_LINK)
# Retriving the Data
sent_data = request.get_json()['data']
name = sent_data['name']
userID = sent_data['userID']
# Process to go between base64 string to bytes, to a file object
imageString = stor_bucket.blob(PATH_TO_FULL_SIZE_IMAGE).download_as_string()
imageFile = BytesIO(imageString)
image = Image.open(imageFile)
# Resizing the image is the goal
image = image.resize(THUMBNAIL_SIZE)
# Go between pillow Image object to a file
imageFile = BytesIO()
image.save(imageFile, format='PNG')
imageBytes = imageFile.getvalue()
image64 = base64.b64encode(imageBytes)
imageFile.seek(0)
# Uploading the Data
other_blob = stor_bucket.blob(PATH_FOR_THUMBNAIL_IMAGE)
other_blob.upload_from_file(imageFile, content_type = 'image/png')
return {'data': {'response': 'ok', 'status': 200}}
Again, this works. I have a feeling there is something wrong with the MIME type. I am a novice when it comes to this type of programming/networking/image manipulation, so I'm always looking for a better way to do this. Anyway, thanks for any and all help.
It appears that the premise of this question - that a access token must be made manually for the image to work - is not accurate. After further testing, the error came from other parts of the code base I was working in. The above python script does work for image manipulation. An access token to the image can be generated via code, and be provided client-side.
Leaving this up in case someone stumbles upon it in the future when they need to work with Pillow/PIL in the Google Cloud Platform.

Where does Custom Vision store training images

I developed an Image Classification Model in CustomVision.AI
I want to download all of the training images used to train the model
I used the training API and was able to retrieve the "HTML" location of all the images however I'd like to use a script to actually download the image to a local drive from the HTML location but am not great with writing scripts as much as running them.
I was also trying to figure out if the images are stored in an azure resource or are custom vision uses its own load storage the images, I'd like to move the images over to an azure blob.
I'm not really a "Programmer" really more of a high-level technology manager but I am comfortable in running scripts and some python code.
I was also trying to figure out if the images are stored in an azure
resource
I suppose it's , cause the images are stored in blob after I checked the image uri. You could use browser developer tool(F12) directly to check the picture uri. The uri format is blob url with image id.
If you want to get all images uri you could use this api: GetTaggedImages and GetUntaggedImages, it will return all images information including the uri.

In DialogFlow, is it possible to output an image from a local file instead of by URL?

I have seen examples in Google's DialogFlow where "Cards" are output and an image is shown to the user. I am using Python as a backend, with ngrok hosting a local website to connect the webhook to Google's fulfillment. However, these cards require an image's URL to show the image after an intent is activated. I am using matplotlib to generate a plot, which is saved locally. I want this image to be displayed after an intent is achieved.
Would it be better to immediately save this plot online somehow, or to send it to ngrok's server for me to use in fulfillment? Or is it possible to just upload the local file?

Is there a way to resize jpgs via http in python?

I am writing a webcrawler that finds and saves the urls of all the images on a website. I can get these without problem. I need to upload these urls, along with a thumbnail version of them, to a server via http request, which will render the image and collect feature information to use in various AI applications.
For some urls this works no problem.
http://images.asos-media.com/products/asos-waxed-parka-raincoat-with-zip-detail/7260214-1-khaki
resizes into
http://images.asos-media.com/products/asos-waxed-parka-raincoat-with-zip-detail/7260214-1-khaki?wid=200
but for actual .jpg images this method doesn't work, like for this one:
https://cdn-images.farfetch-contents.com/11/85/29/57/11852957_8811276_480.jpg
How can I resize the jpgs via url?
Resizing the image via the URL only works if the site you're hitting is using a dynamic media service or tool in their stack. That's why ASOS will allow you to append a query with the dimensions for resize, however different DM tools will have different query parameters.
If you want to make it tolerant you're best off downloading the image, resizing it with Python and then uploading it.

Categories