Skip to content

goneyacine/Eden-AI-CSharp-Code-Snippet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

57 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

EdenAI Code Snippet

this repository contains code snippet and quickstart guide for EdenAI API with C#

Content

Text

  • Quickstart with Spell Check API

Before you start you should make sure to instal Microsoft.AspNet.WebApi.Client

using System;
using System.Threading.Tasks;
using System.Net.Http;
using System.Net.Http.Headers;
public class Program
{

    static void Main(string[] args)
    {
        Console.WriteLine("Spell Check Started...");
        HttpClient httpClient = new HttpClient();
       

        HttpRequestMessage request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("https://api.edenai.run/v2/text/spell_check"),
            Headers =
            {
               { "accept", "application/json" },
            },
            Content = new StringContent("{\"response_as_dict\":true,\"attributes_as_list\":false,\"show_original_response\":false,\"providers\":\"microsoft\",\"text\":\"helowe world,ths is a txte\",\"language\":\"en\"}")
            {
                Headers =
                {
                  ContentType = new MediaTypeHeaderValue("application/json")
                }
            }
        };


        //pass your api key here 
        request.Headers.Add("Authorization", "Bearer πŸ”‘ Your_API_Key");


        using (HttpResponseMessage response = httpClient.Send(request))
        {
            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("succeeded...");
               Console.Write(response.Content.ReadAsStringAsync().Result);
            }
            else
            {
                Console.WriteLine("failed...");
                Console.WriteLine(response.StatusCode.ToString());
            }
        }

        Console.ReadLine();
    }


  
}

  • Quickstart with Text Summarization API

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
    public class TextSummarization
{
    static void Main(string[] args)
    {
        HttpClient httpClient = new HttpClient();


        HttpRequestMessage request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("https://api.edenai.run/v2/text/summarize"),
            Headers =
            {
               { "accept", "application/json" },
            },
            Content = new StringContent("{ \"providers\": \"openai\",\"language\": \"en\",\"text\": \"text to summarize here\"}")
            {
                Headers =
                {
                  ContentType = new MediaTypeHeaderValue("application/json")
                }
            }
        };


        //pass your api key here 
        request.Headers.Add("Authorization", "Bearer Your_Api_Key_Here");


        using (HttpResponseMessage response = httpClient.Send(request))
        {
                JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
                Console.WriteLine((string)json["openai"]["result"]);

                if(!response.IsSuccessStatusCode)
                Console.WriteLine(response.Content);
        }

        Console.ReadLine();
    }
}

  • Quickstart with Code Generation API

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
public class CodeGeneration
{
    static void Main(string[] args)
    {
        HttpClient httpClient = new HttpClient();


        HttpRequestMessage request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("https://api.edenai.run/v2/text/code_generation"),
            Headers =
            {
               { "accept", "application/json" },
            },
            Content = new StringContent("{ \"providers\": \"openai\",\"promot\": \"\",\"instruction\": \"write a code in c++ to calculate distance between to points in 4D space\",\"temprature\" : 0.1,\"max_tokens\":500}")
            {
                Headers =
                {
                  ContentType = new MediaTypeHeaderValue("application/json")
                }
            }
        };


        //pass your api key here 
        request.Headers.Add("Authorization", "Bearer Your_Api_Key_Here");


        using (HttpResponseMessage response = httpClient.Send(request))
        {
            JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
            Console.WriteLine((string)json["openai"]["generated_text"]);

            if (!response.IsSuccessStatusCode)
                Console.WriteLine(response.Content);
        }

        Console.ReadLine();
    }
}

  • Quickstart with Text Generation API

    using System;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using Newtonsoft.Json.Linq;
     public class TextGeneration
     {
          static void Main(string[] args)
          {
          HttpClient httpClient = new HttpClient();
    
    
          HttpRequestMessage request = new HttpRequestMessage
          {
              Method = HttpMethod.Post,
              RequestUri = new Uri("https://api.edenai.run/v2/text/generation"),
              Headers =
              {
                 { "accept", "application/json" },
              },
              Content = new StringContent("{ \"providers\": \"openai\",\"text\": \"put your text here\",\"temprature\" : 0.1,\"max_tokens\":500}")
              {
                  Headers =
                  {
                    ContentType = new MediaTypeHeaderValue("application/json")
                  }
              }
          };
    
    
          //pass your api key here 
          request.Headers.Add("Authorization", "Bearer Your_Api_Key_Here");
    
    
          using (HttpResponseMessage response = httpClient.Send(request))
          {
              JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
              Console.WriteLine((string)json["openai"]["generated_text"]);
    
              if (!response.IsSuccessStatusCode)
                  Console.WriteLine(response.Content);
          }
    
          Console.ReadLine();
    
      }
      }

    • Quickstart with Topic Extraction API

    using System;
    using System.Net.Http;
    using System.Net.Http.Headers;
    using Newtonsoft.Json.Linq;
    public class TopicExtraction
    {
        static void Main(string[] args)
        {
        HttpClient httpClient = new HttpClient();
    
    
        HttpRequestMessage request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("https://api.edenai.run/v2/text/topic_extraction"),
            Headers =
            {
               { "accept", "application/json" },
            },
            Content = new StringContent("{ \"providers\": \"google\",\"text\": \"That actor on TV makes movies in Hollywood and also stars in a variety of popular new TV shows.\",\"language\" : \"en\"}")
            {
                Headers =
                {
                  ContentType = new MediaTypeHeaderValue("application/json")
                }
            }
        };
    
    
        //pass your api key here 
        request.Headers.Add("Authorization", "Bearer YOUR_API_KEY_HERE");
    
    
        using (HttpResponseMessage response = httpClient.Send(request))
        {
            JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
            Console.WriteLine((json["google"]["items"]).ToString());
    
            if (!response.IsSuccessStatusCode)
                Console.WriteLine(response.Content);
        }
    
        Console.ReadLine();
    
    }
    }

  • Quickstart with Search API

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Xml.Linq;
using Newtonsoft.Json.Linq;
public class Search
    {
        static void Main(string[] args)
        {
        HttpClient httpClient = new HttpClient();

       

        HttpRequestMessage request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("https://api.edenai.run/v2/text/search"),
            Headers =
            {
               { "accept", "application/json" },
            },
            Content = new StringContent("{ \"providers\": \"openai\",\"texts\":[\"text one here , keyword\",\" text two here \"],\"query\" : \"keyword\"}")
            {
                Headers =
                {
                  ContentType = new MediaTypeHeaderValue("application/json")
                }
            }
        };


        //pass your api key here 
        request.Headers.Add("Authorization", "Bearer YOUR_API_KEY_HERE");


        using (HttpResponseMessage response = httpClient.Send(request))
        {
            JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
            Console.WriteLine((json["openai"]["items"]).ToString());

            if (!response.IsSuccessStatusCode)
                Console.WriteLine(response.Content);
        }

        Console.ReadLine();

    }
}

  using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Xml.Linq;
using Newtonsoft.Json.Linq;
public class SyntaxAnalysis
{
    static void Main(string[] args)
    {
        HttpClient httpClient = new HttpClient();



        HttpRequestMessage request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("https://api.edenai.run/v2/text/syntax_analysis"),
            Headers =
            {
               { "accept", "application/json" },
            },
            Content = new StringContent("{ \"providers\": \"google\",\"text\":\"put yourw texte heree,\" ,\"language\" : \"en\"}")
            {
                Headers =
                {
                  ContentType = new MediaTypeHeaderValue("application/json")
                }
            }
        };


        //pass your api key here 
        request.Headers.Add("Authorization", "Bearer YOUR_API_KEY_HERE");


        using (HttpResponseMessage response = httpClient.Send(request))
        {
            JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
            Console.WriteLine((json["google"]["items"]).ToString());

            if (!response.IsSuccessStatusCode)
                Console.WriteLine(response.Content);
        }

        Console.ReadLine();

    }
}

  • Quickstart with Keyword Extraction API

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
public class KeyWordExtraction
{
    static void Main(string[] args)
    {
        HttpClient httpClient = new HttpClient();



        HttpRequestMessage request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("https://api.edenai.run/v2/text/keyword_extraction"),
            Headers =
            {
               { "accept", "application/json" },
            },
            Content = new StringContent("{ \"providers\": \"amazon\",\"text\":\"put your text here,\" ,\"language\" : \"en\"}")
            {
                Headers =
                {
                  ContentType = new MediaTypeHeaderValue("application/json")
                }
            }
        };


        //pass your api key here 
        request.Headers.Add("Authorization", "Bearer YOUR_API_KEY_HERE");


        using (HttpResponseMessage response = httpClient.Send(request))
        {
            JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
            Console.WriteLine((json["amazon"]["items"]).ToString());

            if (!response.IsSuccessStatusCode)
                Console.WriteLine(response.Content);
        }

        Console.ReadLine();

    }
}

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
public class TextModeration
    {
    static void Main(string[] args)
    {
        HttpClient httpClient = new HttpClient();



        HttpRequestMessage request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("https://api.edenai.run/v2/text/moderation"),
            Headers =
            {
               { "accept", "application/json" },
            },
            Content = new StringContent("{ \"providers\": \"openai\",\"text\":\"put your text here,\" ,\"language\" : \"en\"}")
            {
                Headers =
                {
                  ContentType = new MediaTypeHeaderValue("application/json")
                }
            }
        };


        //pass your api key here 
        request.Headers.Add("Authorization", "Bearer YOUR_API_KEY_HERE");


        using (HttpResponseMessage response = httpClient.Send(request))
        {
            JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
            Console.WriteLine((json["openai"]["items"]).ToString());

            if (!response.IsSuccessStatusCode)
                Console.WriteLine(response.Content);
        }

        Console.ReadLine();

    }
}

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
public class SentimentAnalysis
{
   static void Main(string[] args)
   {
       HttpClient httpClient = new HttpClient();



       HttpRequestMessage request = new HttpRequestMessage
       {
           Method = HttpMethod.Post,
           RequestUri = new Uri("https://api.edenai.run/v2/text/sentiment_analysis"),
           Headers =
           {
              { "accept", "application/json" },
           },
           Content = new StringContent("{ \"providers\": \"google\",\"text\":\"put your text here,\" ,\"language\" : \"en\"}")
           {
               Headers =
               {
                 ContentType = new MediaTypeHeaderValue("application/json")
               }
           }
       };


       //pass your api key here 
       request.Headers.Add("Authorization", "Bearer YOUR_API_KEY_HERE");


       using (HttpResponseMessage response = httpClient.Send(request))
       {
           JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
           Console.WriteLine((json["google"]["items"]).ToString());

           if (!response.IsSuccessStatusCode)
               Console.WriteLine(response.Content);
       }

       Console.ReadLine();

   }

}

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
public class CustomEntityExtraction
    {
    static void Main(string[] args)
    {
        HttpClient httpClient = new HttpClient();



        HttpRequestMessage request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("https://api.edenai.run/v2/text/custom_named_entity_recognition"),
            Headers =
            {
               { "accept", "application/json" },
            },
            Content = new StringContent("{ \"providers\": \"openai\",\"entities\": [\"person\", \"date\"],\"text\":\"I was born in Lyon in February 1996\" ,\"language\" : \"en\"}")
            {
                Headers =
                {
                  ContentType = new MediaTypeHeaderValue("application/json")
                }
            }
        };


        //pass your api key here 
        request.Headers.Add("Authorization", "Bearer Your_Api_Key_Here");


        using (HttpResponseMessage response = httpClient.Send(request))
        {
            JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
            Console.WriteLine((json["openai"]["items"]).ToString());

            if (!response.IsSuccessStatusCode)
                Console.WriteLine(response.Content);
        }

        Console.ReadLine();

    }

}

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
public class NamedEntityRecognition
    {
        static void Main(string[] args)
        {

        HttpClient httpClient = new HttpClient();



        HttpRequestMessage request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("https://api.edenai.run/v2/text/named_entity_recognition"),
            Headers =
            {
               { "accept", "application/json" },
            },
            Content = new StringContent("{ \"providers\": \"google\",\"text\":\"I was born in Lyon in February 1996\" ,\"language\" : \"en\"}")
            {
                Headers =
                {
                  ContentType = new MediaTypeHeaderValue("application/json")
                }
            }
        };


        //pass your api key here 
        request.Headers.Add("Authorization", "Bearer Your_Api_Key_Here");


        using (HttpResponseMessage response = httpClient.Send(request))
        {
            JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
            Console.WriteLine((json["google"]["items"]).ToString());

            if (!response.IsSuccessStatusCode)
                Console.WriteLine(response.Content);
        }

        Console.ReadLine();

    }
}

  • Quickstart with Question Answering API

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Xml.Linq;
using Newtonsoft.Json.Linq;
public class QuestionAnswering
    {
    static void Main(string[] args)
    {

        HttpClient httpClient = new HttpClient();



        HttpRequestMessage request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("https://api.edenai.run/v2/text/question_answer"),
            Headers =
            {
               { "accept", "application/json" },
            },
            Content = new StringContent("{\"providers\": \"openai\", \"texts\":[\"Linux is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds.\", \"Just like Windows, iOS, and Mac OS, Linux is an operating system. \"],\"question\":\"What is a competitor of Linux?\", \"examples_context\":\"In 2017, U.S. life expectancy was 78.6 years.\", \"examples\":[[\"What is human life expectancy in the United States?\", \"78 years.\"]]}")
            {
                Headers =
                {
                  ContentType = new MediaTypeHeaderValue("application/json")
                }
            }
        };


        //pass your api key here 
        request.Headers.Add("Authorization", "Bearer Your_Api_Key_Here");


        using (HttpResponseMessage response = httpClient.Send(request))
        {
            JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
            Console.WriteLine((json["openai"]["answers"]).ToString());

            if (!response.IsSuccessStatusCode)
                Console.WriteLine(response.Content);
        }

        Console.ReadLine();

    }
}

    using System;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
public class Program
    {
    static void Main(string[] args)
    {

        HttpClient httpClient = new HttpClient();



        HttpRequestMessage request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("https://api.edenai.run/v2/text/anonymization"),
            Headers =
            {
               { "accept", "application/json" },
            },
            Content = new StringContent("{\"providers\": \"openai\",\"text\": \"Hey I am Dave and this is test\"}")
            {
                Headers =
                {
                  ContentType = new MediaTypeHeaderValue("application/json")
                }
            }
        };


        //pass your api key here 
        request.Headers.Add("Authorization", "Bearer YOUR_API_KEY_HERE");


        using (HttpResponseMessage response = httpClient.Send(request))
        {
            JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
            Console.WriteLine((json["openai"]["result"]).ToString());

            if (!response.IsSuccessStatusCode)
                Console.WriteLine(response.Content);
        }

        Console.ReadLine();

    }
}

using System;
using System.Net.Http;
using Newtonsoft.Json.Linq;
using System.Net.Http.Headers;
public class CustomTextClassification
{
    static void Main(string[] args)
    {

        HttpClient httpClient = new HttpClient();



        HttpRequestMessage request = new HttpRequestMessage
        {
            Method = HttpMethod.Post,
            RequestUri = new Uri("https://api.edenai.run/v2/text/custom_classification"),
            Headers =
            {
               { "accept", "application/json" },
            },
            Content = new StringContent("{\"providers\": \"openai\"," +
            " \"labels\": [\"span\", \"not spam\"]," +
            "\"texts\": [\"Confirm your email address\",\"hey i need u to send some $\"]," +
            "\"examples\": [[ \"I need help please wire me $1000 right now\", \"spam\" ]," +
            "[ \"Dermatologists dont like her!\", \"spam\" ]," +
            "[ \"Pre-read for tomorrow\", \"not spam\" ]," +
            "[ \"Your parcel will be delivered today\", \"not spam\" ]]}")
            {
                Headers =
                {
                  ContentType = new MediaTypeHeaderValue("application/json")
                }
            }
        };


        //pass your api key here 
        request.Headers.Add("Authorization", "Bearer your_api_key_here");

        using (HttpResponseMessage response = httpClient.Send(request))
        {
            JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
            Console.WriteLine((json).ToString());

            if (!response.IsSuccessStatusCode)
                Console.WriteLine(response.Content);
        }

        Console.ReadLine();

    }
}

Audio

  • Quickstart with Speech To Text API

Before you start you should make sure to instal Microsoft.AspNet.WebApi.Client

using System;
using System.IO;
using System.Threading;
using System.Net.Http;
using System.Net.Http.Json;
 public class Program
{    
    static void Main(string[] args)
    {
        Console.WriteLine("Speech To Text Started...");

        string filePath = "Your File Path Here";
        string apiKey = "Bearer πŸ”‘ Your_API_Key";


        HttpClient httpClient = new HttpClient();

        //Speech To Text Job Lunch here
        MultipartFormDataContent content = new MultipartFormDataContent();

        content.Add(new StreamContent(File.OpenRead(filePath)),"file",Path.GetFileName(filePath));
        content.Add(new StringContent("microsoft"),"providers");
        content.Add(new StringContent("en"), "language");

        HttpRequestMessage jobLunchRequest = new HttpRequestMessage(HttpMethod.Post, new Uri("https://api.edenai.run/v2/audio/speech_to_text_async"));
        jobLunchRequest.Content = content;

       
        jobLunchRequest.Headers.Add("Authorization", apiKey);


        string public_id = "";
        using (HttpResponseMessage response = httpClient.Send(jobLunchRequest))
        {
            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("job lunch succeeded");
                JobLunchResults results = response.Content.ReadFromJsonAsync<JobLunchResults>().Result;
                public_id = results.Public_id;
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
            }
            else
            {
                Console.WriteLine("job lunch failed");
                Console.WriteLine(response.StatusCode.ToString());
            }
        }
 
        //Speech to text get job results here

        //waiting until speech processing is finished to get the results (we make a request every 5 seconds)
        while (true)
        {
            HttpRequestMessage jobResultsRequest = new HttpRequestMessage(HttpMethod.Get, new Uri($"https://api.edenai.run/v2/audio/speech_to_text_async/{public_id}"));
            jobResultsRequest.Headers.Add("Authorization", apiKey);
            using (HttpResponseMessage response = httpClient.Send(jobResultsRequest))
            {
                if (response.IsSuccessStatusCode)
                {
                    JobGetResults jobGetResults = response.Content.ReadFromJsonAsync<JobGetResults>().Result;
                    if (jobGetResults.Status == "finished" )
                    {
                        Console.WriteLine("get job results succeeded");
                        Console.WriteLine(response.Content.ReadAsStringAsync().Result);
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("get job results failed");
                    Console.WriteLine(response.StatusCode.ToString());
                    break;
                }

            }
            Console.WriteLine("Still Processing...");
            Thread.Sleep(5000);
        }

        
        Console.ReadLine();
    }
    
      public class JobLunchResults
    {
        public string Public_id { get; set; } = "";
    }
    public class JobGetResults
    {
        public string Status { get; set; } = "";
    }
    
}

  • Quickstart with Text To Speech API

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json.Linq;
public class TextToSpeech
{
     static void Main(string[] args)
     {

     HttpClient httpClient = new HttpClient();


     HttpRequestMessage request = new HttpRequestMessage
     {
         Method = HttpMethod.Post,
         RequestUri = new Uri("https://api.edenai.run/v2/audio/text_to_speech"),
         Headers =
         {
            { "accept", "application/json" },
         },
         Content = new StringContent("{ \"providers\": \"google\", \"language\": \"en-US\", \"option\":\"MALE\", \"text\": \"this is a test\"}")
         {
             Headers =
             {
               ContentType = new MediaTypeHeaderValue("application/json")
             }
         }
     };


     //pass your api key here 
     request.Headers.Add("Authorization", "Bearer Your_Api_Key_Here");


     using (HttpResponseMessage response = httpClient.Send(request))
     {
         if (response.IsSuccessStatusCode)
         {
             JObject json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
             byte[] bytes = Convert.FromBase64String((string)json["google"]["audio"]); // convert string to byte array

             //saving audio file
             using (FileStream fs = new FileStream("audio_file.wav", FileMode.CreateNew))
             {
                 fs.Write(bytes, 0, bytes.Length); 
             }
         }
         else
         {
             Console.WriteLine("failed...");
             Console.WriteLine(response.StatusCode.ToString());
         }
     }

     Console.ReadLine();
 }
}

OCR

  • Quickstart with OCR Tables API

Before you start you should make sure to instal Microsoft.AspNet.WebApi.Client

using System;
using System.IO;
using System.Threading;
using System.Net.Http;
using System.Net.Http.Json;
public class Program
{

    static void Main(string[] args)
    {
        Console.WriteLine("OCR Tables Started...");

        string filePath = "Your File Path Here";
        string apiKey = "Bearer πŸ”‘ Your_API_Key";


        HttpClient httpClient = new HttpClient();

        //OCR tables Job Lunch here
        MultipartFormDataContent content = new MultipartFormDataContent();

        content.Add(new StreamContent(File.OpenRead(filePath)), "file", Path.GetFileName(filePath));
        content.Add(new StringContent("microsoft"), "providers");
        content.Add(new StringContent("en"), "language");

        HttpRequestMessage jobLunchRequest = new HttpRequestMessage(HttpMethod.Post, new Uri("https://api.edenai.run/v2/ocr/ocr_tables_async"));
        jobLunchRequest.Content = content;

        
        jobLunchRequest.Headers.Add("Authorization", apiKey);


        string public_id = "";
        using (HttpResponseMessage response = httpClient.Send(jobLunchRequest))
        {
            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("job lunch succeeded");
                JobLunchResults results = response.Content.ReadFromJsonAsync<JobLunchResults>().Result;
                public_id = results.Public_id;
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
            }
            else
            {
                Console.WriteLine("job lunch failed");
                Console.WriteLine(response.StatusCode.ToString());
            }
        }
        //ORC tables get job results here

        //waiting until orc table processing is finished to get the results (we make a request every 5 seconds)
        while (true)
        {
            HttpRequestMessage jobResultsRequest = new HttpRequestMessage(HttpMethod.Get, new Uri($"https://api.edenai.run/v2/ocr/ocr_tables_async/{public_id}"));
            jobResultsRequest.Headers.Add("Authorization", apiKey);
            using (HttpResponseMessage response = httpClient.Send(jobResultsRequest))
            {
                if (response.IsSuccessStatusCode)
                {
                    JobGetResults jobGetResults = response.Content.ReadFromJsonAsync<JobGetResults>().Result;
                    if (jobGetResults.Status == "finished")
                    {
                        Console.WriteLine("get job results succeeded");
                        Console.WriteLine(response.Content.ReadAsStringAsync().Result);
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("get job results failed");
                    Console.WriteLine(response.StatusCode.ToString());
                    break;
                }

            }
            Console.WriteLine("Still Processing...");
            Thread.Sleep(5000);
        }


        Console.ReadLine();
    }

    public class JobLunchResults
    {
        public string Public_id { get; set; } = "";
    }
    public class JobGetResults
    {
        public string Status { get; set; } = "";
    }


}

Releases

No releases published

Packages

No packages published

Languages