Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline | |
| class Emotionclass: | |
| def __init__(self, model: str): | |
| self.model = AutoModelForSequenceClassification.from_pretrained(model) | |
| self.pipeline = pipeline( | |
| "text-classification", | |
| model=self.model, | |
| return_all_scores=True, | |
| ) | |
| def predict(self, input: str): | |
| output = self.pipeline(input)[0] | |
| result = { | |
| "sad": output[0]["score"], | |
| "joy": output[1]["score"], | |
| "love": output[2]["score"], | |
| "anger": output[3]["score"], | |
| "fear": output[4]["score"], | |
| "surprise": output[5]["score"], | |
| } | |
| return result | |
| def main(): | |
| model = Emotionclass("bhadresh-savani/bert-base-uncased-emotion") | |
| iface = gr.Interface( | |
| fn=model.predict, | |
| inputs="text", | |
| outputs=["text"], | |
| title="Sentiment Classification", | |
| ) | |
| iface.launch() | |
| if __name__ == "__main__": | |
| main() |