Spaces:
Runtime error
Runtime error
File size: 4,436 Bytes
5097da2 786ddf5 5097da2 010ea7e 5097da2 a170c3e 5097da2 d8a6cf0 5097da2 d8a6cf0 5097da2 d8a6cf0 5097da2 04b7a0c d8a6cf0 5097da2 786ddf5 b761a34 d3149c4 b761a34 786ddf5 5097da2 d3149c4 5097da2 |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
import streamlit as st
import numpy as np
import pandas as pd
import os
import torch
import torch.nn as nn
from transformers import AutoTokenizer, AutoModelWithLMHead
from transformers.activations import get_activation
st.title('Informal to Formal:')
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
st.text('''Check out this other space: https://huggingface.co/spaces/BigSalmon/GPT2Space''')
st.text('''How To Make Prompt:
informal english: netflix made a ton of money through squidgame, only spending a few millions, while it became a internationally loved show.
Translated into the Style of Abraham Lincoln: netflix reaped handsome profits from squid game, committing only a small sum of money while basking in international acclaim.
Translated into the Style of Abraham Lincoln: ponying but a paltry sum to its production, netflix nevertheless reaped exorbitant returns from squid game amid its overwhelming reception that resounded around the globe.
informal english: garage band has made people who know nothing about music good at creating music.
Translated into the Style of Abraham Lincoln: garage band ( offers the uninitiated in music the ability to produce professional-quality compositions / catapults those for whom music is an uncharted art the ability the realize masterpieces / stimulates music novice's competency to yield sublime arrangements / begets individuals of rudimentary musical talent the proficiency to fashion elaborate suites ).
informal english: chrome extensions can make doing regular tasks much easier to get done.
Translated into the Style of Abraham Lincoln: chrome extensions ( yield the boon of time-saving convenience / ( expedite the ability to / unlock the means to more readily ) accomplish everyday tasks / turbocharges the velocity with which one can conduct their obligations ).
informal english: broadband is finally expanding to rural areas, a great development that will thrust them into modern life.
Translated into the Style of Abraham Lincoln: broadband is ( ( finally / at last / after years of delay ) arriving in remote locations / springing to life in far-flung outposts / inching into even the most backwater corners of the nation ) that will ( hasten their transition into the modern age / leap-frog them into the twenty-first century / facilitate their integration into contemporary life ).
informal english: national parks are a big part of the us culture.
Translated into the Style of Abraham Lincoln: the culture of the united states is ( inextricably ( bound up with / molded by / enriched by / enlivened by ) its ( serene / picturesque / pristine / breathtaking ) national parks ).
informal english: corn fields are all across illinois, visible once you leave chicago.
Translated into the Style of Abraham Lincoln: corn fields ( permeate illinois / span the state of illinois / ( occupy / persist in ) all corners of illinois / line the horizon of illinois / envelop the landscape of illinois ), manifesting themselves visibly as one ventures beyond chicago.
informal english:''')
@st.cache(allow_output_mutation=True)
def get_model():
#tokenizer = AutoTokenizer.from_pretrained("gpt2")
#model = AutoModelWithLMHead.from_pretrained("BigSalmon/MrLincoln12")
#model = AutoModelWithLMHead.from_pretrained("BigSalmon/Points")
tokenizer = AutoTokenizer.from_pretrained("BigSalmon/InformalToFormalLincoln91Paraphrase")
model = AutoModelForCausalLM.from_pretrained("BigSalmon/InformalToFormalLincoln91Paraphrase")
return model, tokenizer
model, tokenizer = get_model()
with st.form(key='my_form'):
prompt = st.text_area(label='Enter sentence')
submit_button = st.form_submit_button(label='Submit')
if submit_button:
with torch.no_grad():
text = tokenizer.encode(prompt)
myinput, past_key_values = torch.tensor([text]), None
myinput = myinput
myinput= myinput.to(device)
logits, past_key_values = model(myinput, past_key_values = past_key_values, return_dict=False)
logits = logits[0,-1]
probabilities = torch.nn.functional.softmax(logits)
best_logits, best_indices = logits.topk(100)
best_words = [tokenizer.decode([idx.item()]) for idx in best_indices]
text.append(best_indices[0].item())
best_probabilities = probabilities[best_indices].tolist()
words = []
st.write(best_words) |