File size: 1,178 Bytes
bf398a7
c52ae65
bf398a7
c52ae65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
import gradio as gr
from transformers import pipeline

# Load the classification pipeline
classifier = pipeline(
    "sentiment-analysis", 
    model="Karzan/user_profile_skills_model", 
    return_all_scores=True, 
    top_k=10
)

# Define the prediction function
def classify_text(text):
    # Perform classification
    results = classifier(text)
    # Format the output
    formatted_results = [
        {"label": item["label"], "score": round(item["score"], 4)}
        for result in results for item in result
    ]
    return formatted_results

# Create the Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# Text Classification with Hugging Face Transformers")
    gr.Markdown("Enter text to classify using the model: **Karzan/user_profile_skills_model**.")
    with gr.Row():
        with gr.Column():
            input_text = gr.Textbox(label="Input Text", lines=3, placeholder="Type something...")
            classify_button = gr.Button("Classify")
        with gr.Column():
            output_text = gr.JSON(label="Classification Results")

    classify_button.click(classify_text, inputs=input_text, outputs=output_text)

# Launch the app
demo.launch()