Spaces:
Sleeping
Sleeping
File size: 888 Bytes
e985d10 858d489 ca3a7ac 858d489 ed01eb1 ca3a7ac 858d489 ca3a7ac 858d489 0210768 ca3a7ac 858d489 ca3a7ac 858d489 27f9d96 |
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 |
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()
|