import json import gradio as gr from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification model_name = "michellejieli/emotion_text_classifier" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForSequenceClassification.from_pretrained(model_name) classifier = pipeline(task="text-classification", model=model, tokenizer=tokenizer, top_k=None) def get_chatbot_response(sentences_json): sentences = json.loads(sentences_json) model_outputs = classifier(sentences) return json.dumps(model_outputs) # produces a list of dicts for each of the labels # Create the Gradio interface app = gr.Interface( fn=get_chatbot_response, inputs=gr.Textbox(label="Your message (JSON format)", lines=5, placeholder='[{"user": "Hi!"}]'), outputs=gr.Textbox(label="System response"), ) if __name__ == "__main__": app.launch()