Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import BertForSequenceClassification, BertTokenizerFast, pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
model_path = "indiaai-text-classification-model"
|
| 5 |
+
model = BertForSequenceClassification.from_pretrained(model_path)
|
| 6 |
+
tokenizer = BertTokenizerFast.from_pretrained(model_path)
|
| 7 |
+
nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer, device="cuda")
|
| 8 |
+
|
| 9 |
+
def classify_text(input_text):
|
| 10 |
+
result = nlp(input_text)
|
| 11 |
+
label = result[0]['label']
|
| 12 |
+
score = result[0]['score']
|
| 13 |
+
output = f"**Prediction:** {label}\n\n**Confidence Score:** {score:.5f}"
|
| 14 |
+
return output
|
| 15 |
+
|
| 16 |
+
interface = gr.Interface(
|
| 17 |
+
fn=classify_text,
|
| 18 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your complaint"),
|
| 19 |
+
outputs=gr.outputs.Markdown(),
|
| 20 |
+
title="INDIAai CyberGuard",
|
| 21 |
+
description="Categorizes cyber complaints based on the victim, type of fraud, and other relevant parameters.",
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
interface.launch()
|