Spaces:
Runtime error
Runtime error
made the output in table format
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ from transformers import AutoModelForSequenceClassification,AutoTokenizer
|
|
| 2 |
from torch.nn.functional import softmax
|
| 3 |
import torch
|
| 4 |
import gradio as gr
|
|
|
|
| 5 |
|
| 6 |
model_name="nebiyu29/hate_classifier"
|
| 7 |
tokenizer=AutoTokenizer.from_pretrained(model_name)
|
|
@@ -20,16 +21,26 @@ def model_classifier(text):
|
|
| 20 |
probs_label=softmax(logits,dim=-1) #turning the probability distribution into normalize form
|
| 21 |
id2label=model.config.id2label
|
| 22 |
return_probs={id2label[i]:probs.item() for i,probs in enumerate(probs_label[0])}
|
| 23 |
-
return return_probs
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
#lets write something that accepts input as text and returns the most likely out come out of 3
|
| 29 |
demo=gr.Interface(
|
| 30 |
fn=model_classifier,
|
| 31 |
inputs=gr.Textbox(lines=5,label="Enter you text"),
|
| 32 |
-
outputs=
|
| 33 |
title="Hate Classifier Demo App"
|
| 34 |
)
|
| 35 |
demo.launch(share=True)
|
|
|
|
| 2 |
from torch.nn.functional import softmax
|
| 3 |
import torch
|
| 4 |
import gradio as gr
|
| 5 |
+
import json
|
| 6 |
|
| 7 |
model_name="nebiyu29/hate_classifier"
|
| 8 |
tokenizer=AutoTokenizer.from_pretrained(model_name)
|
|
|
|
| 21 |
probs_label=softmax(logits,dim=-1) #turning the probability distribution into normalize form
|
| 22 |
id2label=model.config.id2label
|
| 23 |
return_probs={id2label[i]:probs.item() for i,probs in enumerate(probs_label[0])}
|
| 24 |
+
return json.dumps(list(return_probs.items()))
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
+
#lets define how the output looks like
|
| 30 |
+
output_format=gr.Table(label="label probabilities",
|
| 31 |
+
columns=["label","probabilities"],
|
| 32 |
+
type="table",
|
| 33 |
+
show_index=False,
|
| 34 |
+
input_type="json",
|
| 35 |
+
max_rows=4,
|
| 36 |
+
max_columms=2
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
#lets write something that accepts input as text and returns the most likely out come out of 3
|
| 40 |
demo=gr.Interface(
|
| 41 |
fn=model_classifier,
|
| 42 |
inputs=gr.Textbox(lines=5,label="Enter you text"),
|
| 43 |
+
outputs=output_format,
|
| 44 |
title="Hate Classifier Demo App"
|
| 45 |
)
|
| 46 |
demo.launch(share=True)
|