Download app.py from AmirRghp/IMDB_Comment_Classification: direct link, hf CLI and curl.
- Browser
- Download file 692 Bytes
-
https://huggingface.co/spaces/AmirRghp/IMDB_Comment_Classification/resolve/main/app.py
- Command line
-
hf download hf://spaces/AmirRghp/IMDB_Comment_Classification/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AmirRghp/IMDB_Comment_Classification/resolve/main/app.py
692 Bytes
| 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('AmirRghp/distilbert-base-uncasedimdb-text-classification') | |
| # Create the pipeline | |
| classifier = pipeline('text-classification', model=model, tokenizer=tokenizer) | |
| def classify_text(text): | |
| result = classifier(text) | |
| return result | |
| gr.Interface(fn=classify_text, inputs="text", outputs="json").launch() | |