Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,16 @@
|
|
| 1 |
# URL: https://huggingface.co/spaces/gradio/text_generation
|
| 2 |
# imports
|
| 3 |
import gradio as gr
|
| 4 |
-
from transformers import
|
| 5 |
-
import torch
|
| 6 |
|
| 7 |
# loading the model
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
# defining the core function
|
| 12 |
def generate(text):
|
| 13 |
-
|
| 14 |
-
result = generation_pipeline(text)
|
| 15 |
return result[0]["generated_text"]
|
| 16 |
|
| 17 |
|
|
|
|
| 1 |
# URL: https://huggingface.co/spaces/gradio/text_generation
|
| 2 |
# imports
|
| 3 |
import gradio as gr
|
| 4 |
+
from transformers import pipeline, set_seed
|
|
|
|
| 5 |
|
| 6 |
# loading the model
|
| 7 |
+
generator = pipeline('text-generation', model='gpt2')
|
| 8 |
+
set_seed(42)
|
| 9 |
+
|
| 10 |
|
| 11 |
# defining the core function
|
| 12 |
def generate(text):
|
| 13 |
+
generator(text, max_length=30, num_return_sequences=1)
|
|
|
|
| 14 |
return result[0]["generated_text"]
|
| 15 |
|
| 16 |
|