Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,15 @@ tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
|
|
| 7 |
model = GPT2LMHeadModel.from_pretrained("gpt2")
|
| 8 |
|
| 9 |
def generate_text(prompt, max_length, temperature, top_k, top_p):
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
iface = gr.Interface(
|
| 13 |
fn=generate_text,
|
|
@@ -20,4 +28,4 @@ iface = gr.Interface(
|
|
| 20 |
],
|
| 21 |
outputs="text"
|
| 22 |
)
|
| 23 |
-
iface.launch()
|
|
|
|
| 7 |
model = GPT2LMHeadModel.from_pretrained("gpt2")
|
| 8 |
|
| 9 |
def generate_text(prompt, max_length, temperature, top_k, top_p):
|
| 10 |
+
inputs = tokenizer.encode(prompt, return_tensors="pt")
|
| 11 |
+
outputs = model.generate(inputs,
|
| 12 |
+
max_length=max_length,
|
| 13 |
+
temperature=temperature,
|
| 14 |
+
top_k=top_k,
|
| 15 |
+
top_p=top_p,
|
| 16 |
+
num_return_sequences=1)
|
| 17 |
+
text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 18 |
+
return text
|
| 19 |
|
| 20 |
iface = gr.Interface(
|
| 21 |
fn=generate_text,
|
|
|
|
| 28 |
],
|
| 29 |
outputs="text"
|
| 30 |
)
|
| 31 |
+
iface.launch()
|