Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
import os
|
5 |
+
import torch
|
6 |
+
import torch.nn as nn
|
7 |
+
from transformers.activations import get_activation
|
8 |
+
from transformers import AutoTokenizer, AutoModelWithLMHead, AutoModelForCausalLM
|
9 |
+
|
10 |
+
st.title('GPT2:')
|
11 |
+
#device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
12 |
+
number_of_outputs = st.sidebar.slider("Number of Outputs", 50, 350)
|
13 |
+
|
14 |
+
@st.cache(allow_output_mutation=True)
|
15 |
+
def get_model():
|
16 |
+
#model = #AutoModelWithLMHead.from_pretrained("BigSalmon/GPTNeo350MInformalToFormalLincoln6")
|
17 |
+
#model = AutoModelWithLMHead.from_pretrained("BigSalmon/GPTNeo350MInformalToFormalLincoln5")
|
18 |
+
#model = AutoModelWithLMHead.from_pretrained("BigSalmon/GPTNeo350MInformalToFormalLincoln4")
|
19 |
+
#model = AutoModelWithLMHead.from_pretrained("BigSalmon/GPTNeo350MInformalToFormalLincoln3")
|
20 |
+
#model = AutoModelWithLMHead.from_pretrained("BigSalmon/GPTNeo350MInformalToFormalLincoln2")
|
21 |
+
#model = AutoModelWithLMHead.from_pretrained("BigSalmon/GPTNeo350MInformalToFormalLincoln")
|
22 |
+
#model = AutoModelWithLMHead.from_pretrained("BigSalmon/InformalToFormalLincoln24")
|
23 |
+
#model = AutoModelWithLMHead.from_pretrained("BigSalmon/InformalToFormalLincoln25")
|
24 |
+
#model = AutoModelWithLMHead.from_pretrained("BigSalmon/InformalToFormalLincoln26")
|
25 |
+
#model = AutoModelWithLMHead.from_pretrained("BigSalmon/InformalToFormalLincoln27")
|
26 |
+
#model = AutoModelWithLMHead.from_pretrained("BigSalmon/InformalToFormalLincoln28")
|
27 |
+
#model = AutoModelWithLMHead.from_pretrained("BigSalmon/InformalToFormalLincoln29")
|
28 |
+
#model = AutoModelForCausalLM.from_pretrained("BigSalmon/InformalToFormalLincoln30")
|
29 |
+
#model = AutoModelForCausalLM.from_pretrained("BigSalmon/InformalToFormalLincoln31")
|
30 |
+
#model = AutoModelForCausalLM.from_pretrained("BigSalmon/InformalToFormalLincoln32")
|
31 |
+
#model = AutoModelForCausalLM.from_pretrained("BigSalmon/InformalToFormalLincoln33")
|
32 |
+
#model = AutoModelForCausalLM.from_pretrained("BigSalmon/InformalToFormalLincoln34")
|
33 |
+
#model = AutoModelForCausalLM.from_pretrained("BigSalmon/InformalToFormalLincoln35")
|
34 |
+
#model = AutoModelForCausalLM.from_pretrained("BigSalmon/Points4")
|
35 |
+
tokenizer = AutoTokenizer.from_pretrained("BigSalmon/GPT2Neo1.3BPoints")
|
36 |
+
model = AutoModelForCausalLM.from_pretrained("BigSalmon/GPT2Neo1.3BPoints")
|
37 |
+
return model, tokenizer
|
38 |
+
|
39 |
+
model, tokenizer = get_model()
|
40 |
+
g = """informal english: garage band has made people who know nothing about music good at creating music.
|
41 |
+
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 ).
|
42 |
+
informal english: chrome extensions can make doing regular tasks much easier to get done.
|
43 |
+
|
44 |
+
***
|
45 |
+
|
46 |
+
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 ).
|
47 |
+
informal english: broadband is finally expanding to rural areas, a great development that will thrust them into modern life.
|
48 |
+
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 leap-frog them into the twenty-first century.
|
49 |
+
|
50 |
+
***
|
51 |
+
|
52 |
+
informal english: google translate has made talking to people who do not share your language easier.
|
53 |
+
Translated into the Style of Abraham Lincoln: google translate ( imparts communicability to individuals whose native tongue differs / mitigates the trials of communication across linguistic barriers / hastens the bridging of semantic boundaries / mollifies the complexity of multilingual communication / avails itself to the internationalization of discussion / flexes its muscles to abet intercultural conversation / calms the tides of linguistic divergence ).
|
54 |
+
|
55 |
+
***
|
56 |
+
|
57 |
+
informal english: corn fields are all across illinois, visible once you leave chicago.
|
58 |
+
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.
|
59 |
+
|
60 |
+
***
|
61 |
+
|
62 |
+
informal english: """
|
63 |
+
with st.form(key='my_form'):
|
64 |
+
prompt = st.text_area(label='Enter sentence', value=g)
|
65 |
+
submit_button = st.form_submit_button(label='Submit')
|
66 |
+
if submit_button:
|
67 |
+
with torch.no_grad():
|
68 |
+
text = tokenizer.encode(prompt)
|
69 |
+
myinput, past_key_values = torch.tensor([text]), None
|
70 |
+
myinput = myinput
|
71 |
+
#myinput= myinput
|
72 |
+
logits, past_key_values = model(myinput, past_key_values = past_key_values, return_dict=False)
|
73 |
+
logits = logits[0,-1]
|
74 |
+
probabilities = torch.nn.functional.softmax(logits)
|
75 |
+
best_logits, best_indices = logits.topk(number_of_outputs)
|
76 |
+
best_words = [tokenizer.decode([idx.item()]) for idx in best_indices]
|
77 |
+
text.append(best_indices[0].item())
|
78 |
+
best_probabilities = probabilities[best_indices].tolist()
|
79 |
+
words = []
|
80 |
+
st.write(best_words)
|