Update .venv/PythonProjectFile1.py
Browse files- .venv/PythonProjectFile1.py +10 -10
.venv/PythonProjectFile1.py
CHANGED
|
@@ -2,19 +2,19 @@ from transformers import pipeline, DistilBertTokenizer, DistilBertForSequenceCla
|
|
| 2 |
import torch
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
|
| 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 |
-
|
| 12 |
-
|
| 13 |
-
|
| 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="
|
| 20 |
iface.launch()
|
|
|
|
| 2 |
import torch
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
myPipe = 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 |
+
return myPipe(prompt)[0]
|
| 12 |
+
# inputs = tokenizer(prompt, return_tensors="pt")
|
| 13 |
+
# with torch.no_grad():
|
| 14 |
+
# logits = model(**inputs).logits
|
| 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=gr.Textbox(label="Your Text:"), outputs=gr.Textbox(label="Valence Score:"))
|
| 20 |
iface.launch()
|