Spaces:
Build error
Build error
TextGenereation
Browse files
app.py
CHANGED
|
@@ -1,18 +1,15 @@
|
|
| 1 |
-
from transformers import
|
| 2 |
import gradio as grad
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
labels=grad.Textbox(lines=1, label="Label", placeholder="Input a Label")
|
| 17 |
-
out=grad.Textbox(lines=1, label="Probablity of label being true is")
|
| 18 |
-
grad.Interface(classify, inputs=[txt,labels], outputs=out).launch()
|
|
|
|
| 1 |
+
from transformers import GPT2LMHeadModel,GPT2Tokenizer
|
| 2 |
import gradio as grad
|
| 3 |
|
| 4 |
+
mdl = GPT2LMHeadModel.from_pretrained('gpt2')
|
| 5 |
+
gpt2_tkn=GPT2Tokenizer.from_pretrained('gpt2')
|
| 6 |
|
| 7 |
+
def generate(starting_text):
|
| 8 |
+
tkn_ids = gpt2_tkn.encode(starting_text, return_tensors = 'pt')
|
| 9 |
+
gpt2_tensors = mdl.generate(tkn_ids)
|
| 10 |
+
response = gpt2_tensors
|
| 11 |
+
return response
|
| 12 |
+
|
| 13 |
+
txt=grad.Textbox(lines=1, label="English", placeholder="English Text here")
|
| 14 |
+
out=grad.Textbox(lines=1, label="Generated Tensors")
|
| 15 |
+
grad.Interface(generate, inputs=txt, outputs=out).launch()
|
|
|
|
|
|
|
|
|