Spaces:
Runtime error
Runtime error
File size: 1,631 Bytes
8f56860 29b7792 8f56860 29b7792 8f56860 29b7792 8f56860 097f905 8f56860 cb6bb4c 6794af1 cb6bb4c 8f56860 1f0b456 8f56860 65d5acb 29b7792 |
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 28 29 30 31 32 33 34 35 36 37 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
choices = ['Formal to Informal', 'Informal to Formal']
tokenizer_1 = AutoTokenizer.from_pretrained('prithivida/formal_to_informal_styletransfer')
model_1 = AutoModelForSeq2SeqLM.from_pretrained('prithivida/formal_to_informal_styletransfer')
tokenizer_2 = AutoTokenizer.from_pretrained('prithivida/informal_to_formal_styletransfer')
model_2 = AutoModelForSeq2SeqLM.from_pretrained('prithivida/informal_to_formal_styletransfer')
def model_selection(choices, text):
if choices == "Formal to Informal":
inputs = tokenizer_1.encode(text, return_tensors = 'pt')
outputs = model_1.generate(inputs)
clean = tokenizer_1.decode(outputs[0])
else:
inputs = tokenizer_2.encode(text, return_tensors = 'pt')
outputs = model_2.generate(inputs)
clean = tokenizer_2.decode(outputs[0])
replace = clean.replace('<pad>', '').replace('</s>', '')
return replace
input_1 = gr.inputs.Radio(choices = choices, label='Choose a model.')
input_2 = gr.inputs.Textbox(placeholder='Enter your text here...', label = 'Input')
article = "<p style='text-align: center'><a href='https://github.com/PrithivirajDamodaran/Styleformer'>Styleformer GitHub</a></p>"
examples = [["Formal to Informal", "Your mother is so old that her last name is asaurus."], ["Informal to Formal", "Yo what's up with the weather?"]]
iface = gr.Interface(
model_selection,
[input_1, input_2], "text", theme = 'huggingface', article=article, examples = examples)
if __name__ == "__main__":
iface.launch() |