File size: 865 Bytes
15994c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7840a71
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr
from transformers import pipeline

# Load your model
classifier = pipeline("text-classification", model="sachin6624/bert-trainer")

# Map labels to custom messages
label_mapping = {
    "LABEL_1": "The sentences are paraphrases (similar in meaning).",
    "LABEL_0": "The sentences are not paraphrases (different in meaning)."
}

# Custom prediction function
def predict(sentence1, sentence2):
    input_text = f"{sentence1} [SEP] {sentence2}"
    result = classifier(input_text)
    label = result[0]["label"]
    # Return the custom message for the predicted label
    return label_mapping.get(label, "Unknown label")

# Gradio interface
interface = gr.Interface(
    fn=predict,
    inputs=["text", "text"],
    outputs="text",  # Output is text for custom messages
    title="Paraphrase Classification"
)

# Launch the app
interface.launch()