![| Embarcadero RAD Studio Delphi C++Builder Blogs](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/05/smartmockups_kop0uk35-2847808-scaled.jpg?resize=1140%2C694&ssl=1)
The AI API “Fast Style” is a form of graphical style transfer which uses a neural network to combine the artistic styles of one image with another to render a new unique image. You can think of it as taking a photograph and combining it with a Manet painting to produce a unique photo after the style of Manet.
To make art, we will use the help of DeepAi.org a platform that you can use to make a lot of artificial intelligence projects. One of them is “fast style transfer”. We will connect with their API using a Windows Application Development: Delphi Software.
Table of Contents
REST and Delphi makes the API easy to use
Delphi has a tool called REST Debugger that makes it easy to connect with a REST API. After using it and successfully make the connection, you can copy the components into your Delphi application. Let’s dive into the DeepAi API and see how to build a desktop application to make art.
How to connect with DeepAi API?
DeepAi has good documentation around their API, which you can check here. First of all, you will need to make an account on DeepAi.org and take your API key. You are gonna need it later.
![deepaiprofileapikey4125428 | Embarcadero RAD Studio Delphi C++Builder Blogs DeepAi Fast Style API 1](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/05/deepai-profile-api-key-4125428.png?resize=652%2C250&ssl=1)
From the Fast Style documentation, you can see that you will need to send three parameters to the API endpoint. Two links or files with images (where one is the image to render and the other, the style you want to apply), and your API key.
![deepaiapiendpoints1938225 | Embarcadero RAD Studio Delphi C++Builder Blogs DeepAi Fast Style API Curl examples](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/05/deepai-api-endpoints-1938225.png?resize=711%2C301&ssl=1)
How do I use Delphi to Connect with DeepAi API REST endpoints ?
First of all, let’s use the REST Debugger found in RAD Studio Delphi. The REST Debugger is a visual tool to connect with any API, make a call, and get a response. In your Delphi IDE,. To use it, in the IDE menu, go to Tools > REST Debugger.
![delphirestdebugger8919805 | Embarcadero RAD Studio Delphi C++Builder Blogs DeepAi Fast Style API in the Delphi REST debugger](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/05/delphi-rest-debugger-8919805.png?resize=750%2C511&ssl=1)
Change the Method to POST and insert the API Endpoint ( https://api.deepai.org/api/fast-style ) in the URL field. Then, go to the Parameters Tab. To add the image links, click on the Add button. If you want to send a link directly from a web link, on Kind, select BODY. If you want to send a file of your hard drive, select FILE instead. In the name, write ‘content’ and put the link of the image in the value. For your style image, just change the name to ‘style’. Lastly, click on add again e now, select HEADER on Kind and, on name, write api-key and on value, put your API key value.
Sending a REST request to the DeepAI API
![delphirestdebuggerconfig4312725 | Embarcadero RAD Studio Delphi C++Builder Blogs Sending a REST request to the DeepAi Fast Style API with Delphi](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/05/delphi-rest-debugger-config-4312725.png?resize=750%2C229&ssl=1)
Now, click on Send Request and after some time, you should receive a 200 response and, on Tabular Data Tab, you will see the output_url, with the link of the image that the artificial intelligence created:
![delphirestdebuggerresult2928525 | Embarcadero RAD Studio Delphi C++Builder Blogs DeepAi Fast Style API REST response](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/05/delphi-rest-debugger-result-2928525.png?resize=750%2C188&ssl=1)
Congrats, now you can send and get data from an Artificial Intelligence API and use it as you want.
Get valuable insights on how clean and sharp photos are when implementing an image upscale using DeepAI’s Super Resolution API.
How do I build a Windows desktop application to send and get images from the DeepAi API?
The application we are gonna build here will get the images from your computer, show and send them to the deepAi API. Also, it will show the image that the API returns and save it into the application folder. So, with a form already created, paste the components copied from the REST Debugger.
![delphicomponents3321543 | Embarcadero RAD Studio Delphi C++Builder Blogs DeepAi Fast Style API required Delphi REST components](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/05/delphi-components-3321543.png?resize=530%2C174&ssl=1)
Right-click on the RESTRequest1 component and execute it. After right-clicking on the FDMemTable1 component, go to Fields Editor > Add All Fields. I added more components to make the app. Your form should look similar to this:
![faststyleappcomponents6072304 | Embarcadero RAD Studio Delphi C++Builder Blogs DeepAi Fast Style API example Delphi form](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/05/fast-style-app-components-6072304.png?resize=750%2C413&ssl=1)
Connecting a REST request with the API
Now, let’s go to the code. To connect with the API you can use:
1 2 3 4 5 6 7 |
FDMemTable1.Close; RESTRequest1.Params[0].Value := mainImgFile; RESTRequest1.Params[2].Value := styleImgFile; RESTRequest1.Execute; FDMemTable1.Open; GetImg(FDMemTable1OUTPUT_URL.AsString); |
To process the result and download the image, we created the GetImg procedure. There you can do something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
MS := TMemoryStream.Create; IdHTTP1 := TIdHTTP.Create(nil); IMG := TJPEGImage.Create; MS.Clear; IdHTTP1.Get(urls, MS); MS.Position := 0; MS.SaveToFile(resourcesDirectory + 'output.jpg'); IMG.LoadFromStream(MS); ImgResult.Picture.Assign(IMG); Application.ProcessMessages; IMG.Free; MS.Free; |
Here’s an example of the final DeepAI Fast Style API results from our Delphi app
![faststyleappresult5806138 | Embarcadero RAD Studio Delphi C++Builder Blogs DeepAi Fast Style API Result](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/05/fast-style-app-result-5806138-7365133.jpg?resize=750%2C409&ssl=1)
You can check all the code here: https://github.com/brunomileto/deepai_api
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition