Skip to content

Instantly share code, notes, and snippets.

@juucustodio
Last active May 30, 2019 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juucustodio/420973ff3603f0eedf329ab22699d907 to your computer and use it in GitHub Desktop.
Save juucustodio/420973ff3603f0eedf329ab22699d907 to your computer and use it in GitHub Desktop.
Example of how to use framework de Machine Learning ML.NET in your Xamarin.Forms applications - http://julianocustodio.com/utilizando-ml-net-em-aplicacoes-xamarin-forms
using System;
using System.ComponentModel;
using System.Net.Http;
using Newtonsoft.Json;
using Xamarin.Forms;
namespace DemoCommentary
{
[DesignTimeVisible(true)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
public async void GetResult(object sender, EventArgs e)
{
if (String.IsNullOrWhiteSpace(Texto.Text))
return;
using (var client = new HttpClient())
{
client.Timeout = new TimeSpan(0, 0, 0, 30);
var request = new HttpRequestMessage
{
RequestUri = new Uri("http://192.168.0.3:5000/api/commentary/" + Texto.Text),
Method = HttpMethod.Get
};
var result = await client.SendAsync(request);
if (!result.IsSuccessStatusCode)
throw new Exception(result.Content.ReadAsStringAsync().Result);
var json = result.Content.ReadAsStringAsync().Result;
var data = JsonConvert.DeserializeObject<PredictionResult>(json);
if (data.Predicition)
Emoji.Source = "happy.png";
else
Emoji.Source = "sad.png";
LblResult.Text = $"Predicition:{data.Predicition}\nScore:{data.Score}\nProbability: {data.Probability}";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment