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_with_bars(text): # Perform classification results = classifier(text) # Prepare data for bar chart labels = [] scores = [] for result in results: for item in result: labels.append(item["label"]) scores.append(item["score"]) return {label: score for label, score in zip(labels, scores)} # Create the Gradio interface with gr.Blocks() as demo: gr.Markdown("# Text Classification with Bar Chart Output") gr.Markdown("Enter text to classify, and view predictions with their scores in a bar chart.") 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_chart = gr.Label(label="Classification Results (Bar Chart)", type="plot") classify_button.click(classify_text_with_bars, inputs=input_text, outputs=output_chart) # Launch the app demo.launch()