Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example of how to use framework de Machine Learning ML.NET in your Xamarin.Forms applications -
using System;
using System.ComponentModel;
using System.Net.Http;
using Newtonsoft.Json;
using Xamarin.Forms;
namespace DemoCommentary
public partial class MainPage : ContentPage
public MainPage()
public async void GetResult(object sender, EventArgs e)
if (String.IsNullOrWhiteSpace(Texto.Text))
using (var client = new HttpClient())
client.Timeout = new TimeSpan(0, 0, 0, 30);
var request = new HttpRequestMessage
RequestUri = new Uri("" + 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";
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