Spaces:
Sleeping
Sleeping
update app.py 3
Browse files
app.py
CHANGED
|
@@ -1,4 +1,9 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)
|
| 3 |
model = AutoModelForSequenceClassification.from_pretrained(model_id)
|
| 4 |
|
|
@@ -10,13 +15,13 @@ def classify(text):
|
|
| 10 |
predicted_class = torch.argmax(logits, dim=1).item()
|
| 11 |
return str(predicted_class)
|
| 12 |
|
| 13 |
-
#
|
| 14 |
demo = gr.Interface(
|
| 15 |
fn=classify,
|
| 16 |
inputs=gr.Textbox(label="Enter text"),
|
| 17 |
outputs=gr.Textbox(label="Prediction")
|
| 18 |
)
|
| 19 |
|
| 20 |
-
# β
Enable
|
| 21 |
-
demo.queue()
|
| 22 |
-
demo.launch(show_api=True)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification # β
required
|
| 4 |
+
|
| 5 |
+
# Load model
|
| 6 |
+
model_id = "Rerandaka/Cild_safety_bigbird"
|
| 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 |
+
# API-ready Gradio Interface
|
| 19 |
demo = gr.Interface(
|
| 20 |
fn=classify,
|
| 21 |
inputs=gr.Textbox(label="Enter text"),
|
| 22 |
outputs=gr.Textbox(label="Prediction")
|
| 23 |
)
|
| 24 |
|
| 25 |
+
# β
Enable API and queue
|
| 26 |
+
demo.queue()
|
| 27 |
+
demo.launch(show_api=True)
|