Spaces:
Running
Running
File size: 816 Bytes
05086cb 318e432 05086cb 318e432 b24c622 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]["label"]
return prediction
# Create a Gradio interface
iface = gr.Interface(
fn=classify_text,
inputs=gradio.components.Textbox(label="Enter text"),
outputs=gr.outputs.Label(label="Predicted classes"),
)
# Launch the Gradio app
iface.launch() |