Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pickle
|
3 |
+
from huggingface_hub import hf_hub_download
|
4 |
+
|
5 |
+
model_path = hf_hub_download(repo_id="alperugurcan/toxic-model", filename="toxic_model.pkl")
|
6 |
+
vectorizer_path = hf_hub_download(repo_id="alperugurcan/toxic-model", filename="toxic_vectorizer.pkl")
|
7 |
+
|
8 |
+
model = pickle.load(open(model_path, 'rb'))
|
9 |
+
vectorizer = pickle.load(open(vectorizer_path, 'rb'))
|
10 |
+
|
11 |
+
def predict(text):
|
12 |
+
features = vectorizer.transform([text.lower()])
|
13 |
+
predictions = model.predict_proba(features)
|
14 |
+
|
15 |
+
labels = ['toxic', 'severe_toxic', 'obscene', 'threat', 'insult', 'identity_hate']
|
16 |
+
return {label: float(pred[0][1]) for label, pred in zip(labels, predictions)}
|
17 |
+
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=predict,
|
20 |
+
inputs="text",
|
21 |
+
outputs="label",
|
22 |
+
title="Toxic Comment Classifier"
|
23 |
+
)
|
24 |
+
|
25 |
+
iface.launch()
|