Spaces:
Sleeping
Sleeping
API case bn
Browse files
app.py
CHANGED
@@ -2,8 +2,8 @@ import gradio as gr
|
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
import torch
|
4 |
|
5 |
-
# Load model
|
6 |
-
model_id = "Rerandaka/
|
7 |
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)
|
8 |
model = AutoModelForSequenceClassification.from_pretrained(model_id)
|
9 |
|
@@ -15,14 +15,19 @@ def classify(text):
|
|
15 |
predicted_class = torch.argmax(logits, dim=1).item()
|
16 |
return str(predicted_class)
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
inputs=gr.Textbox(label="Text Input"),
|
22 |
-
outputs=gr.Textbox(label="Prediction"),
|
23 |
-
title="Child-Safety Text Classifier",
|
24 |
-
description="This model detects unsafe or inappropriate text for children."
|
25 |
-
)
|
26 |
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
import torch
|
4 |
|
5 |
+
# Load model and tokenizer
|
6 |
+
model_id = "Rerandaka/Child_safty_bigbird_1"
|
7 |
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)
|
8 |
model = AutoModelForSequenceClassification.from_pretrained(model_id)
|
9 |
|
|
|
15 |
predicted_class = torch.argmax(logits, dim=1).item()
|
16 |
return str(predicted_class)
|
17 |
|
18 |
+
# Use Blocks to define interface and API
|
19 |
+
with gr.Blocks() as demo:
|
20 |
+
gr.Markdown("## Child-Safety Text Classifier\nThis model detects unsafe or inappropriate text for children.")
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
with gr.Row():
|
23 |
+
input_box = gr.Textbox(label="Enter text to classify")
|
24 |
+
output_box = gr.Textbox(label="Prediction")
|
25 |
+
|
26 |
+
btn = gr.Button("Submit")
|
27 |
+
btn.click(fn=classify, inputs=input_box, outputs=output_box)
|
28 |
+
|
29 |
+
# ✅ Named API endpoint
|
30 |
+
demo.load(fn=classify, inputs=input_box, outputs=output_box, api_name="predict")
|
31 |
+
|
32 |
+
# Launch space
|
33 |
+
demo.launch()
|