Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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,
|
11 |
set_seed(seed)
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
grad.Interface(fn=generate, inputs=txt, outputs=out,
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
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)
|