Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| import torch | |
| import numpy as np | |
| model_name = "ungsumalindd/my-model-upload" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForSequenceClassification.from_pretrained(model_name) | |
| model.eval() | |
| labels = ["swelling","redness","rash","bump","itch", | |
| "hives","acne"] | |
| def predict(text): | |
| inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True).to(model.device) | |
| with torch.no_grad(): | |
| outputs = model(**inputs) | |
| probs = torch.sigmoid(outputs.logits)[0].cpu().numpy() | |
| max_idx = int(np.argmax(probs)) | |
| max_label = labels[max_idx] | |
| max_score = round(probs[max_idx] * 100) | |
| return f"{max_label} ({max_score}%)" | |
| gr.Interface( | |
| fn=predict, | |
| inputs=gr.Textbox(label="Enter english comment"), | |
| outputs=gr.Text(label="Top Emotion") | |
| ).launch() |