Last active
May 30, 2019 16:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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