Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
3 |
+
|
4 |
+
# Load model and tokenizer
|
5 |
+
model_name = "peterkros/immunization-classification-model"
|
6 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Define the pipeline
|
10 |
+
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
11 |
+
|
12 |
+
def classify_text(text):
|
13 |
+
# Get predictions
|
14 |
+
predictions = classifier(text)
|
15 |
+
return predictions
|
16 |
+
|
17 |
+
# Create Gradio interface
|
18 |
+
iface = gr.Interface(
|
19 |
+
fn=classify_text,
|
20 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
|
21 |
+
outputs=gr.outputs.JSON(),
|
22 |
+
title="Text Classification with DistilBERT",
|
23 |
+
description="Enter text to classify it using a DistilBERT model trained for text classification."
|
24 |
+
)
|
25 |
+
|
26 |
+
# Launch the app
|
27 |
+
if __name__ == "__main__":
|
28 |
+
iface.launch()
|