aliabd HF staff commited on
Commit
d8373c0
Β·
1 Parent(s): ed3287f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
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 GPT2Tokenizer, GPT2Model
5
- import torch
6
 
7
  # loading the model
8
- tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
9
- model = GPT2Model.from_pretrained('gpt2')
 
10
 
11
  # defining the core function
12
  def generate(text):
13
- generation_pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)
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