Update .venv/PythonProjectFile1.py
Browse files- .venv/PythonProjectFile1.py +16 -6
.venv/PythonProjectFile1.py
CHANGED
|
@@ -1,10 +1,20 @@
|
|
| 1 |
-
from transformers import pipeline
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline, DistilBertTokenizer, DistilBertForSequenceClassification
|
| 2 |
+
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
|
| 5 |
+
#generator = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
|
| 6 |
|
| 7 |
+
tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
| 8 |
+
model = DistilBertForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
| 9 |
|
| 10 |
+
def classify_text(prompt):
|
| 11 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 12 |
+
with torch.no_grad():
|
| 13 |
+
logits = model(**inputs).logits
|
| 14 |
|
| 15 |
+
predicted_class_id = logits.argmax().item()
|
| 16 |
+
return model.config.id2label[predicted_class_id]
|
| 17 |
+
|
| 18 |
+
# Create a Gradio interface
|
| 19 |
+
iface = gr.Interface(fn=classify_text, inputs="text", outputs="text")
|
| 20 |
+
iface.launch()
|