Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,22 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
4 |
-
import torch
|
5 |
|
6 |
-
# Load
|
7 |
-
|
8 |
-
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
14 |
-
# Forward pass through the model
|
15 |
-
outputs = model(**inputs)
|
16 |
-
# Get the prediction (0 or 1 for binary classification)
|
17 |
-
prediction = torch.argmax(outputs.logits, dim=1).item()
|
18 |
-
# Map prediction to sentiment labels
|
19 |
-
return "positive" if prediction == 1 else "negative"
|
20 |
|
21 |
-
#
|
22 |
iface = gr.Interface(
|
23 |
-
fn=
|
24 |
-
inputs=gr.Textbox(
|
25 |
-
outputs=
|
26 |
-
title="
|
27 |
-
description="This model
|
28 |
)
|
29 |
|
30 |
-
# Launch
|
31 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
|
|
|
|
3 |
|
4 |
+
# Load pre-trained model for CoLA (linguistic acceptability)
|
5 |
+
model_name = "preetidav/distilbert-base-uncased-finetuned-cola"
|
6 |
+
classifier = pipeline("text-classification", model=model_name)
|
7 |
|
8 |
+
def classify_sentence(sentence):
|
9 |
+
result = classifier(sentence)[0]
|
10 |
+
return f"Label: {result['label']} (Confidence: {result['score']:.2f})"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Create Gradio interface
|
13 |
iface = gr.Interface(
|
14 |
+
fn=classify_sentence,
|
15 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter a sentence..."),
|
16 |
+
outputs="text",
|
17 |
+
title="Sentence Acceptability Classifier",
|
18 |
+
description="This model classifies whether a sentence is linguistically acceptable (LABEL_1) or not (LABEL_0).",
|
19 |
)
|
20 |
|
21 |
+
# Launch app
|
22 |
iface.launch()
|