File size: 915 Bytes
988a1f0 1c55f2c 6dad9e3 49d2fed 6dad9e3 f7ee327 49d2fed 6dad9e3 988a1f0 ae28ea8 988a1f0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
id2label = {0: "Negative", 1: "Positive"}
label2id = {"Negative":0, "Positive":1}
# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained('distilbert/distilbert-base-uncased', add_prefix_space=True)
model = AutoModelForSequenceClassification.from_pretrained(
model="AmirRghp/distilbert-base-uncasedimdb-text-classification", num_labels=2, id2label=id2label, label2id=label2id)
# Create the pipeline
classifier = pipeline('text-classification', model=model, tokenizer=tokenizer)
# Load your model from your Hugging Face profile
classifier = pipeline('text-classification', model='AmirRghp/distilbert-base-uncasedimdb-text-classification')
def classify_text(text):
result = classifier(text)
return result
gr.Interface(fn=classify_text, inputs="text", outputs="json").launch()
|