Question script pour utiliser l'api de colorisation de photo noire et blanc

Plus d'informations
il y a 3 ans 10 mois #29916 par Gabriel
bonsoir a toutes et tous.

après la lecture de l’article Comment coloriser une photo en noir et blanc? sur le site de Korben.info, je suis aller voir le site et il y a plein d'exemples pour jouer avec l'API d'expliqué, sauf ...pour notre language favori :angry:

grosso modo vous téléversez une image en noir et blanc, et l'IA re-colorise l'image


deepai.org/machine-learning-model/colorizer

donc je cherches à utiliser des commandes powershell pour m'en servir. il y a des exemples en python, javascript et c#
$uri = "https://api.deepai.org/api/colorizer"
$file = "C:\Temp\test_colorize\test_noir_et_blanc.png"
$outfile = "C:\Temp\test_colorize\test_noir_et_blanc_colorized.png"
$header = @{"api-key"="quickstart-QUdJIGlzIGNvbWluZy4uLi4K"}

Invoke-WebRequest -Uri $uri -Header $header -InFile "$file" -Method Post -ContentType "application/octet-stream" -TimeoutSec 600

et donc ça marche pas :laugh:
Invoke-WebRequest : {"err": "error processing given inputs from request"}
Au caractère C:\Temp\test_colorize\test.ps1:38 : 1
+ Invoke-WebRequest -Uri $uri -Header $header -InFile "$file" -Method P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation : (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

si il y a des avis, je suis preneur!
merci à vous

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 3 ans 10 mois #29917 par Laurent Dardenne
Salut,
même avec Curl.exe je n'y arrive pas, mais je ne suis pas très doué avec cet outil.
Le site répond :
curl.exe  -I  https://api.deepai.org/api/colorizer

Il cite un exemple en C# avec une de leur dll :
//Image Colorization Csharp Examples

// Ensure your DeepAI.Client NuGet package is up to date: https://www.nuget.org/packages/DeepAI.Client

// Example posting a image URL:
using DeepAI; // Add this line to the top of your file
DeepAI_API api = new DeepAI_API(apiKey: "quickstart-QUdJIGlzIGNvbWluZy4uLi4K");
StandardApiResponse resp = api.callStandardApi("colorizer", new { image = "YOUR_IMAGE_URL",});
Console.Write(api.objectAsJsonString(resp));


// Example posting a local image file:
using DeepAI; // Add this line to the top of your file
DeepAI_API api = new DeepAI_API(apiKey: "quickstart-QUdJIGlzIGNvbWluZy4uLi4K");
StandardApiResponse resp = api.callStandardApi("colorizer", new {  image = File.OpenRead("C:\\path\\to\\your\\file.jpg"),});
Console.Write(api.objectAsJsonString(resp));
Mais je n'ai pas pris le temps de tester.

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 3 ans 10 mois #29918 par Laurent Dardenne
Le projet Github.
Semble être payant et utiliser TLS 1.2.

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 3 ans 10 mois #29919 par Laurent Dardenne

This shortcut uses the DeepAI API and requires an API key. To get an API key, sign up on deepai.org and go to the Dashboard to find your API key.

Note: The API gives you a limited amount of requests for free. The limit is at 1000 requests/50 cents. You get 5 dollars worth of API requests for free when you sign up. The max amount of requests you can make for free is 10,000.


Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 3 ans 10 mois - il y a 3 ans 10 mois #29920 par Gabriel
bonjour Laurent

le curl -I repond un 401 parcequ'il manque la clé APi, je penses
C:\Users\gaby>curl.exe  -I  https://api.deepai.org/api/colorizer
HTTP/1.1 401 Unauthorized
Date: Fri, 19 Jun 2020 18:26:26 GMT
Content-Type: application/json
Content-Length: 78
Connection: keep-alive
Status: 401 Unauthorized
Vary: Origin, Cookie
X-Frame-Options: ALLOWALL
X-Powered-By: Phusion Passenger
Server: nginx + Phusion Passenger

don si on "corrige" (en clair on le rend utilisable sous windows avec curl en virant les simple quote, il m'a fallut un peu de temps)

ca donne
C:\Temp\test_colorize>curl -F image=@C:/Temp/test_colorize/aaa.jpg -H api-key:quickstart-QUdJIGlzIGNvbWluZy4uLi4K https://api.deepai.org/api/colorizer
{
    "id": "60b5501f-3e6b-4213-bbaa-4cb9c9fd8d37",
    "output_url": "https://api.deepai.org/job-view-file/60b5501f-3e6b-4213-bbaa-4cb9c9fd8d37/outputs/output.jpg"
}

donc curl envoie bien le fichier, par contre le invoke-webrequest visiblement envoi les données dans un format que l'api ne comprend pas
Invoke-WebRequest : {"err": "error processing given inputs from request"}

bon je vais chercher dans cette direction...
bonne soirée
Dernière édition: il y a 3 ans 10 mois par Gabriel.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 3 ans 10 mois #29923 par Laurent Dardenne
Avec
add-type @"
     using System.Net;
     using System.Security.Cryptography.X509Certificates;
     public class TrustAllCertsPolicy : ICertificatePolicy {
         public bool CheckValidationResult(
             ServicePoint srvPoint, X509Certificate certificate,
             WebRequest request, int certificateProblem) {
             return true;
         }
     }
"@
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Invoke-RestMethod -Uri $uri -Header $header -InFile $file -Method Put -ContentType 'image/jpg' -TimeoutSec 600
J'obtiens :
Invoke-RestMethod : {"status": "Please pass a valid Api-Key in a HTTP header called \"Api-Key\" "}
A suivre...

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.076 secondes
Propulsé par Kunena