Spaces:
Sleeping
Sleeping
Commit ·
1d4036b
1
Parent(s): 5696f1b
init
Browse files- app.py +23 -0
- model.pkl +3 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Load modules
|
| 2 |
+
from fastai.text.all import *
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Load trained model
|
| 6 |
+
learn = load_learner("model.pkl")
|
| 7 |
+
|
| 8 |
+
# Prepare classifier function and categories
|
| 9 |
+
categories = ("negative", "positive")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def classify_text(text):
|
| 13 |
+
pred, idx, probs = learn.predict(text)
|
| 14 |
+
# Same as {"negative": probs[0], "positive": probs[1]}
|
| 15 |
+
return dict(zip(categories, map(float, probs)))
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# Setup input, output GUI, and algorithm block
|
| 19 |
+
image = gr.inputs.Textbox()
|
| 20 |
+
label = gr.outputs.Label()
|
| 21 |
+
|
| 22 |
+
intf = gr.Interface(fn=classify_text, inputs=image, outputs=label)
|
| 23 |
+
intf.launch(inline=False)
|
model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:47f9a01fc0b58a0aec48014b149083ff066728dc8a94160319d7f038d37ad8d6
|
| 3 |
+
size 131688931
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
fastai==2.7.12
|