doevent commited on
Commit
8d74675
1 Parent(s): ba23862

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -2,20 +2,24 @@ from transformers import pipeline, set_seed
2
  import gradio as grad
3
  import random
4
 
5
-
6
  gpt2_pipe = pipeline('text-generation', model='succinctly/text2image-prompt-generator')
7
 
8
 
9
  def generate(starting_text):
10
- seed = random.randint(1, 10000000)
11
  set_seed(seed)
12
- response= gpt2_pipe(starting_text, max_length=20, num_return_sequences=5)
13
- return response[1]['generated_text']
14
-
15
- txt=grad.Textbox(lines=1, label="English", placeholder="English Text here")
16
- out=grad.Textbox(lines=1, label="Generated Text")
 
 
 
 
 
17
 
18
- grad.Interface(fn=generate, inputs=txt, outputs=out,
19
- allow_flagging='never',
20
- cache_examples=False,
21
- theme="default").launch(enable_queue=True, debug=True)
 
2
  import gradio as grad
3
  import random
4
 
 
5
  gpt2_pipe = pipeline('text-generation', model='succinctly/text2image-prompt-generator')
6
 
7
 
8
  def generate(starting_text):
9
+ seed = random.randint(1, 100000)
10
  set_seed(seed)
11
+ while True:
12
+ response = str(gpt2_pipe(starting_text, max_length=30, num_return_sequences=random.randint(5, 15))).strip()
13
+ if starting_text != response[1]['generated_text']:
14
+ print(f"Repeat: {response}")
15
+ else:
16
+ return response[1]['generated_text']
17
+
18
+
19
+ txt = grad.Textbox(lines=1, label="English", placeholder="English Text here")
20
+ out = grad.Textbox(lines=1, label="Generated Text")
21
 
22
+ grad.Interface(fn=generate, inputs=txt, outputs=out,
23
+ allow_flagging='never',
24
+ cache_examples=False,
25
+ theme="default").launch(enable_queue=True, debug=True)