File size: 872 Bytes
d10f97a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

# Load the model and tokenizer
classifier = pipeline("text-classification",model="AbraMuhara/Fine-TunedBERTURKOfansifTespit")

# Define the prediction function
def classify_text(text):
    # Use the pipeline to classify the text
    result = classifier(text)
    # Extract the label and score
    label = result[0]['label']
    score = result[0]['score']
    return f"Label: {label}\nScore: {score:.4f}"

# Create the Gradio interface
iface = gr.Interface(
    fn=classify_text,          # The function to call for predictions
    inputs=gr.Textbox(),       # Text input box
    outputs=gr.Text(),         # Text output box
    title="Text Classification",  # Title of the app
    description="Enter text to classify it and get the prediction label and score."  # Description
)

# Launch the interface
iface.launch()