from transformers import pipeline import gradio as gr from transformers import AutoTokenizer, AutoModelWithLMHead from os import path MODEL_DIRECTORY = "/models/mrm8488-t5-base-finetuned-emotion" tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-emotion", use_fast=False) if not path.exists(MODEL_DIRECTORY): model = AutoModelWithLMHead.from_pretrained("mrm8488/t5-base-finetuned-emotion") model.save_pretrained(MODEL_DIRECTORY) else: model = AutoModelWithLMHead.from_pretrained(MODEL_DIRECTORY) def get_emotion(text): input_ids = tokenizer.encode(text + '', return_tensors='pt') output = model.generate(input_ids=input_ids, max_length=2) # print(output) dec = [tokenizer.decode(ids) for ids in output] print(dec) label = dec[0] return label def parph(name= "paraphrase: This is something which I cannt understand at all."): #text2text = pipeline("text2text-generation") ##model_name = 'tuner007/pegasus_paraphrase' #text2text = pipeline('text2text-generation', model = "Vamsi/T5_Paraphrase_Paws") ##text2text(name) test = get_emotion("""No doubt, 2020 has been the wackiest year ever. Found my family and my life wreck like never before. I dont only say this because of the job i hate or any family problem i have, but my mom is also planning on moving in with her brother's family just to escape this house full of unemployed people who keeps her unstable with all her cousins and other relatives depending on her. As if a miracle happened, she was now finally, after years, moving out. Well, of course, Im supposed to be with her. But i was planning on working on site by next week, and guess what. She was planning on moving out this weekend. She told me about this just this Monday, I didnt know what to tell her so I asked her to give me time to think.\n\n\n\nI asked her what her plans were after moving in with another family, relative or not it still wasnt going to be our property so i wanted to make sure. She told me we were only temporarily going to move there and then find a place to settle in afterward. I knew this was a terrible idea already, so i asked her, why wont she find a place to rent first while were here so that we can really make sure that we arent going to stay at my relatives for a long time. Eventually, after a lot of asking, she told me that her and my uncle had a talk, and that he told her it was better for her to be on his side, at least no matter what happens they'd be there for each other. \n\n\n\nThat might be sweet and all, but this set up of moving out doesnt even give us independence at all. This uncle of mine had 5 kids, none of them were grown up. The house was noisily irritating, there was no place for peace of mind and all of that. Even if i move my work equipment there, I don't think it would be a comfortable adjustment. \n\nI just think like, this is, again, another foolish decision not being thought through by my mom. I've been stressed a lot enough, and now i have to contemplate this moving out thing. \n\n\n\nI am planning to tell her that I wanted to stay here as Id be working on-site soon. The plan is to have her live in the countryside with my uncle and for me to stay here. But of course, I would be again the one making the foolish decision because in all cases I should choose to always be with my mom, be there to take care of her, and such. But I already have plans for myself, and I cant afford to compromise for a plan that isnt even thought through. How is she going to figure this out when she gets there? It makes no sense.\n\n \n\nA few days more and it's Christmas Time, the house has no decors, everything is uncertain and are in shambles. This couldn't get any worse.""" ) return name # text2text(name) iface = gr.Interface(fn=parph, inputs="text", outputs="text") iface.launch()