PeerChristensen commited on
Commit
2a3c28e
·
1 Parent(s): 9955b64

Add application file

Browse files
Files changed (3) hide show
  1. app.py +36 -0
  2. nb_model.pickle +0 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import joblib
4
+
5
+ model = joblib.load("nb_model.pickle")
6
+
7
+ def return_output(text):
8
+ """Alternative function to output predictions as simple text"""
9
+ output = predict(text)
10
+ output_string = f"Device: {output[0]}\n\nProbability: {output[1]}"
11
+ return output_string
12
+
13
+
14
+ def predict(text):
15
+
16
+ data = pd.DataFrame({"text": [text]})
17
+ #prediction_class = model.predict(data)[0]
18
+ #prediction_prob = round(model.predict_proba(data).max(), 3)
19
+ #return prediction_class, prediction_prob
20
+ pred = model.predict_proba(data)[0]
21
+ return {'Android': pred[0], 'iPhone': pred[1]}
22
+
23
+
24
+ description = "According to the dataset used for this model, Trump mainly uses two devices for tweeting" \
25
+ " - an Android and an iPhone device.\nIt seems likely that members of his staff are tweeting on his" \
26
+ " behalf using iPhone.\nTry and see if you can write an 'iPhone' and an 'Android' tweet."
27
+
28
+ iface = gr.Interface(fn=predict,
29
+ #fn=return_output,
30
+ inputs="text",
31
+ #outputs="text",
32
+ outputs="label",
33
+ allow_flagging=False, title="iPhone or Android?",
34
+ interpretation="default", description=description)
35
+
36
+ iface.launch()
nb_model.pickle ADDED
Binary file (1.45 MB). View file
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pandas
2
+ sklearn
3
+ joblib