人人人人人人人人人人人人

c# 调用DeepAI

包括画卡通画,找出2张图片的相似度,电脑做梦的图片生成,利用GTP-2的文本续写。

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DeepAI;
namespace WpfApp7
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            
        }

        void TestCartoon() {

            // 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("toonify", 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("toonify", new
            {
                image = File.OpenRead(@"C:\Users\gwang\Pictures\1469162215-how-to-read-faces.jpg"),
            });


            Console.Write(api.objectAsJsonString(resp));






        }


        void TestSearchSimil2Image() {


            //DeepAI_API api = new DeepAI_API(apiKey: "quickstart-QUdJIGlzIGNvbWluZy4uLi4K");

            //StandardApiResponse resp = api.callStandardApi("image-similarity", new
            //{
            //    image1 = "YOUR_IMAGE_URL",
            //    image2 = "YOUR_IMAGE_URL",
            //});
            //Console.Write(api.objectAsJsonString(resp));


            // Example posting a local image file:


            DeepAI_API api = new DeepAI_API(apiKey: "quickstart-QUdJIGlzIGNvbWluZy4uLi4K");

            StandardApiResponse resp = api.callStandardApi("image-similarity", new
            {
                image1 = File.OpenRead("C:\\path\\to\\your\\file.jpg"),
                image2 = File.OpenRead("C:\\path\\to\\your\\file.jpg"),
            });
            Console.Write(api.objectAsJsonString(resp));



        }

        void TestDeepDream() {

            // 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("deepdream", 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("deepdream", new
            {
                image = File.OpenRead(@"C:\Users\gwang\Pictures\1469162215-how-to-read-faces.jpg"),
            });
            Console.Write(api.objectAsJsonString(resp));






        }



        void TestTextGeneration() {

            //https://deepai.org/machine-learning-model/text-generator
            // Text Generation Csharp Examples
            // Ensure your DeepAI.Client NuGet package is up to date: https://www.nuget.org/packages/DeepAI.Client
            // Example posting a text 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("text-generator", new
            //{
            //    text = "YOUR_TEXT_URL",
            //});
            //Console.Write(api.objectAsJsonString(resp));


            // Example posting a local text 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("text-generator", new
            //{
            //    text = File.OpenRead("C:\\path\\to\\your\\file.txt"),
            //});
            //Console.Write(api.objectAsJsonString(resp));


            //// Example directly sending a text string:

            //using DeepAI; // Add this line to the top of your file

            DeepAI_API api = new DeepAI_API(apiKey: "quickstart-QUdJIGlzIGNvbWluZy4uLi4K");

            StandardApiResponse resp = api.callStandardApi("text-generator", new
            {
                text = "Three days into the Tokyo 2020 Games, 20 sports will be contested today",
            });
            Console.Write(api.objectAsJsonString(resp));









        }


        private void Button_Click(object sender, RoutedEventArgs e)
        {
            TestTextGeneration();
           // TestDeepDream ();
        }









    }



}

  

posted @ 2021-07-27 16:58  wgscd  阅读(244)  评论(0编辑  收藏  举报