Spaces:
Sleeping
Sleeping
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() | |