king007 commited on
Commit
b459cca
1 Parent(s): 0108d1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import torch
2
  import gradio as gr
 
3
  from transformers import GPT2Tokenizer, GPT2LMHeadModel, pipeline
4
 
5
  tokenizer = GPT2Tokenizer.from_pretrained('distilgpt2')
@@ -14,10 +15,10 @@ nlp = pipeline('text-generation', model=model, tokenizer=tokenizer)
14
  def generate(prompt):
15
  # generate 10 samples using contrastive search
16
  outs = nlp(prompt, max_length=76, num_return_sequences=3, do_sample=True, repetition_penalty=1.2, temperature=0.7, top_k=3, early_stopping=True)
17
- outs_json=outs.to_json(orient="records")
18
  print(prompt)
19
- print(outs_json)
20
- return outs
21
 
22
 
23
  # for i in range(len(outs)):
 
1
  import torch
2
  import gradio as gr
3
+ import json
4
  from transformers import GPT2Tokenizer, GPT2LMHeadModel, pipeline
5
 
6
  tokenizer = GPT2Tokenizer.from_pretrained('distilgpt2')
 
15
  def generate(prompt):
16
  # generate 10 samples using contrastive search
17
  outs = nlp(prompt, max_length=76, num_return_sequences=3, do_sample=True, repetition_penalty=1.2, temperature=0.7, top_k=3, early_stopping=True)
18
+ jsonStr = json.dumps(outs)
19
  print(prompt)
20
+ print(jsonStr)
21
+ return jsonStr
22
 
23
 
24
  # for i in range(len(outs)):