Spaces:
Sleeping
Sleeping
File size: 1,280 Bytes
0a264b8 794ad1f 0a264b8 794ad1f 0a264b8 794ad1f 0a264b8 794ad1f 0a264b8 794ad1f |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import gradio as gr
from transformers import pipeline
# The pipeline will automatically load the model and tokenizer
# from the directory where the app is running.
try:
classifier = pipeline("text-classification", model="./", tokenizer="./")
def classify_text(text):
if not text:
return "Please enter some text to classify."
result = classifier(text)[0]
# Map the default labels to more descriptive ones
label = "Hate Speech" if result['label'] == 'LABEL_1' else "Not Hate Speech"
score = result['score']
return f"Prediction: {label}\nConfidence: {score:.4f}"
iface = gr.Interface(
fn=classify_text,
inputs=gr.Textbox(lines=5, placeholder="Enter a comment in English or Hindi..."),
outputs=gr.Textbox(label="Result"),
title="Multilingual Hate Speech Classifier",
description="A model to classify comments as hate speech or not."
)
iface.launch()
except Exception as e:
gr.Interface(
lambda x: f"An error occurred: {e}",
inputs="text",
outputs="text",
title="Error Loading Model",
description="There was an issue loading the model. Please check your files and dependencies."
).launch()
|