Spaces:
Runtime error
Runtime error
File size: 1,450 Bytes
2a3c28e 170adc3 d0af744 170adc3 2a3c28e b4d7e54 2a3c28e 0ce8340 2a3c28e b4d7e54 2a3c28e 170adc3 2a3c28e 1d4ef16 2a3c28e e7c4368 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import gradio as gr
import pandas as pd
import joblib
import json
from json import encoder
encoder.FLOAT_REPR = lambda o: format(o, '.2f')
model = joblib.load("nb_model.pickle")
'''
def return_output(text):
"""Alternative function to output predictions as simple text"""
output = predict(text)
output_string = f"Device: {str(output[0])}\n\nProbability: {int(output[1])}"
return output_string
'''
def predict(text):
data = pd.DataFrame({"text": [text]})
#prediction_class = model.predict(data)[0]
#prediction_prob = round(model.predict_proba(data).max(), 3)
#return prediction_class, prediction_prob
pred = model.predict_proba(data)[0]
return {'Android': json.dumps(pred[0]), 'iPhone': json.dumps(pred[1])}
description = "According to the dataset used for this model, Trump mainly uses two devices for tweeting" \
" - an Android and an iPhone device.\nIt seems likely that members of his staff are tweeting on his" \
" behalf using iPhone.\nTry and see if you can write an 'iPhone' and an 'Android' tweet."
iface = gr.Interface(fn=predict,
#fn=return_output,
inputs="text",
#outputs="text",
outputs="label",
allow_flagging='auto', title="iPhone or Android?",
interpretation="default", description=description)
iface.launch(enable_queue=True) |