Commit ·
008c18b
1
Parent(s): 54e0cc6
app
Browse files- app.py +20 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased')
|
| 7 |
+
model = DistilBertForSequenceClassification.from_pretrained('jdmartinev/imdbreviews_classification_distilbert_v02')
|
| 8 |
+
id2label = {0: "negative", 1: "positive"}
|
| 9 |
+
|
| 10 |
+
def classify_text(input_text,id2label):
|
| 11 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
| 12 |
+
outputs = model(**inputs)
|
| 13 |
+
pred = np.argmax(outputs)
|
| 14 |
+
return(f"Predicted class: {id2label[pred]}")
|
| 15 |
+
|
| 16 |
+
demo = gr.Interface(classify_text, "text", "text")
|
| 17 |
+
demo.launch()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio
|