Spaces:
Sleeping
Sleeping
first commit
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load your model
|
5 |
+
classifier = pipeline("text-classification", model="sachin6624/bert-trainer")
|
6 |
+
|
7 |
+
# Map labels to custom messages
|
8 |
+
label_mapping = {
|
9 |
+
"LABEL_1": "The sentences are paraphrases (similar in meaning).",
|
10 |
+
"LABEL_0": "The sentences are not paraphrases (different in meaning)."
|
11 |
+
}
|
12 |
+
|
13 |
+
# Custom prediction function
|
14 |
+
def predict(sentence1, sentence2):
|
15 |
+
input_text = f"{sentence1} [SEP] {sentence2}"
|
16 |
+
result = classifier(input_text)
|
17 |
+
label = result[0]["label"]
|
18 |
+
# Return the custom message for the predicted label
|
19 |
+
return label_mapping.get(label, "Unknown label")
|
20 |
+
|
21 |
+
# Gradio interface
|
22 |
+
interface = gr.Interface(
|
23 |
+
fn=predict,
|
24 |
+
inputs=["text", "text"],
|
25 |
+
outputs="text", # Output is text for custom messages
|
26 |
+
title="Paraphrase Classification"
|
27 |
+
)
|
28 |
+
|
29 |
+
# Launch the app
|
30 |
+
interface.launch()
|