Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -123,20 +123,41 @@
|
|
123 |
# out=grad.Textbox(lines=1, label="Probablity of label being true is")
|
124 |
# grad.Interface(classify, inputs=[txt,labels], outputs=out).launch()
|
125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
from transformers import GPT2LMHeadModel,GPT2Tokenizer
|
127 |
import gradio as grad
|
128 |
|
129 |
mdl = GPT2LMHeadModel.from_pretrained('gpt2')
|
130 |
gpt2_tkn=GPT2Tokenizer.from_pretrained('gpt2')
|
131 |
|
|
|
132 |
def generate(starting_text):
|
133 |
tkn_ids = gpt2_tkn.encode(starting_text, return_tensors = 'pt')
|
134 |
gpt2_tensors = mdl.generate(tkn_ids)
|
135 |
-
response
|
|
|
|
|
|
|
136 |
return response
|
|
|
137 |
txt=grad.Textbox(lines=1, label="English", placeholder="English Text here")
|
138 |
out=grad.Textbox(lines=1, label="Generated Tensors")
|
139 |
grad.Interface(generate, inputs=txt, outputs=out).launch()
|
140 |
|
141 |
|
142 |
|
|
|
|
|
|
123 |
# out=grad.Textbox(lines=1, label="Probablity of label being true is")
|
124 |
# grad.Interface(classify, inputs=[txt,labels], outputs=out).launch()
|
125 |
|
126 |
+
# from transformers import GPT2LMHeadModel,GPT2Tokenizer
|
127 |
+
# import gradio as grad
|
128 |
+
|
129 |
+
# mdl = GPT2LMHeadModel.from_pretrained('gpt2')
|
130 |
+
# gpt2_tkn=GPT2Tokenizer.from_pretrained('gpt2')
|
131 |
+
|
132 |
+
# def generate(starting_text):
|
133 |
+
# tkn_ids = gpt2_tkn.encode(starting_text, return_tensors = 'pt')
|
134 |
+
# gpt2_tensors = mdl.generate(tkn_ids)
|
135 |
+
# response = gpt2_tensors
|
136 |
+
# return response
|
137 |
+
# txt=grad.Textbox(lines=1, label="English", placeholder="English Text here")
|
138 |
+
# out=grad.Textbox(lines=1, label="Generated Tensors")
|
139 |
+
# grad.Interface(generate, inputs=txt, outputs=out).launch()
|
140 |
from transformers import GPT2LMHeadModel,GPT2Tokenizer
|
141 |
import gradio as grad
|
142 |
|
143 |
mdl = GPT2LMHeadModel.from_pretrained('gpt2')
|
144 |
gpt2_tkn=GPT2Tokenizer.from_pretrained('gpt2')
|
145 |
|
146 |
+
|
147 |
def generate(starting_text):
|
148 |
tkn_ids = gpt2_tkn.encode(starting_text, return_tensors = 'pt')
|
149 |
gpt2_tensors = mdl.generate(tkn_ids)
|
150 |
+
response=""
|
151 |
+
#response = gpt2_tensors
|
152 |
+
for i, x in enumerate(gpt2_tensors):
|
153 |
+
response=response+f"{i}: {gpt2_tkn.decode(x, skip_special_tokens=True)}"
|
154 |
return response
|
155 |
+
|
156 |
txt=grad.Textbox(lines=1, label="English", placeholder="English Text here")
|
157 |
out=grad.Textbox(lines=1, label="Generated Tensors")
|
158 |
grad.Interface(generate, inputs=txt, outputs=out).launch()
|
159 |
|
160 |
|
161 |
|
162 |
+
|
163 |
+
|