Spaces:
Sleeping
Sleeping
File size: 817 Bytes
05086cb 318e432 05086cb 318e432 35e86ac 318e432 a9e76be 35e86ac 318e432 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import gradio as gr
from transformers import TextClassificationPipeline, AutoTokenizer, AutoModelForSequenceClassification
# Load a pre-trained text classification model
model_name = "KoalaAI/Text-Moderation"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
# Create a TextClassificationPipeline
pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer)
# Define the classify_text function using the pipeline
def classify_text(text):
prediction = pipe(text)[0]
return prediction
# Create a Gradio interface
iface = gr.Interface(
fn=classify_text,
inputs=gr.components.Textbox(label="Enter text"),
outputs=gr.outputs.Label(num_top_classes=None), # Show all labels
)
# Launch the Gradio app
iface.launch() |