zoukankan      html  css  js  c++  java
  • 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:UsersgwangPictures1469162215-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:UsersgwangPictures1469162215-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 ();
            }
    
    
    
    
    
    
    
    
    
        }
    
    
    
    }
    

      

    fffffffffffffffff
    test red font.
  • 相关阅读:
    一个短信验证码倒计时插件
    记一次图片优化经历
    前端开发中两种常见的图片加载方式
    《javascript面向对象精要》读书笔记
    less hack 兼容
    第一次项目总结
    你总说毕业遥遥无期,可转眼就各奔东西
    【翻译】理念:无冲突的扩展本地DOM原型
    【翻译】jQuery是有害的
    202002280156-《统治世界的10种算法(摘自极客大学堂)》
  • 原文地址:https://www.cnblogs.com/wgscd/p/15066825.html
Copyright © 2011-2022 走看看