Spaces:
Sleeping
Sleeping
Download app.py from Rimi98/NegativeCommentClassifier: direct link, hf CLI and curl.
- Browser
- Download file 810 Bytes
-
https://huggingface.co/spaces/Rimi98/NegativeCommentClassifier/resolve/main/app.py
- Command line
-
hf download hf://spaces/Rimi98/NegativeCommentClassifier/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Rimi98/NegativeCommentClassifier/resolve/main/app.py
810 Bytes
| import gradio as gr | |
| import onnxruntime | |
| from transformers import AutoTokenizer | |
| import torch, json | |
| token = AutoTokenizer.from_pretrained('distilroberta-base') | |
| types = ['Toxic','Severe_toxic','Obscene','Threat','Insult','Identity_hate'] | |
| inf_session = onnxruntime.InferenceSession('classifier-quantized.onnx') | |
| input_name = inf_session.get_inputs()[0].name | |
| output_name = inf_session.get_outputs()[0].name | |
| def classify(review): | |
| input_ids = token(review)['input_ids'][:512] | |
| logits = inf_session.run([output_name], {input_name: [input_ids]})[0] | |
| logits = torch.FloatTensor(logits) | |
| probs = torch.sigmoid(logits)[0] | |
| return dict(zip(types, map(float, probs))) | |
| label = gr.outputs.Label(num_top_classes=5) | |
| iface = gr.Interface(fn=classify, inputs="text", outputs=label) | |
| iface.launch(inline=False) |