import gradio as gr from transformers import pipeline pipe = pipeline("text-classification", model="peter2000/xlm-roberta-base-finetuned-ecoicop") def predict(text): preds = pipe(text)[0] return preds["label"].split('_')[1],preds["label"].split('_')[0], round(preds["score"], 5) gradio_ui = gr.Interface( fn=predict, title="Predicting E-Coicop Product Categories", description="Enter some product text (trained on name, category and url) from an online supermarket and predict the corresponding ECOICOP (level 5) product category for food and baverages.", inputs=[ gr.inputs.Textbox(lines=5, label="Paste some text here"), ], outputs=[ gr.outputs.Textbox(label="Label"), gr.outputs.Textbox(label="Score"), ], examples=[ ["Tiefkühl Eiscreme & Eiswürfel Bechereis rewe beste wahl peanut butter eiscreme REWE Beste Wahl Peanut Butter Eiscreme 500ml"], ["epicerie-sucree cereales chocolat fraise nat Céréales chocolat & fraise NAT"], ["Pelati e passate unknown Mutti Polpa di Pomodoro 3 x 400 g"] ], ) gradio_ui.launch(debug=True)