Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,30 @@
|
|
1 |
from transformers import pipeline, set_seed
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
response_list = []
|
13 |
for x in response:
|
14 |
if x['generated_text'].strip() != starting_text:
|
15 |
response_list.append(x['generated_text'])
|
16 |
-
|
17 |
response_end = "\n".join(response_list)
|
18 |
return response_end
|
19 |
|
|
|
1 |
from transformers import pipeline, set_seed
|
2 |
import gradio as grad
|
3 |
import random
|
4 |
+
import re
|
5 |
|
6 |
gpt2_pipe = pipeline('text-generation', model='succinctly/text2image-prompt-generator')
|
7 |
|
8 |
+
with open("name.txt", "r") as f:
|
9 |
+
line = f.readlines()
|
10 |
+
|
11 |
|
12 |
def generate(starting_text):
|
13 |
seed = random.randint(1, 100000)
|
14 |
set_seed(seed)
|
15 |
+
|
16 |
+
# If the text field is empty
|
17 |
+
if starting_text == "":
|
18 |
+
starting_text: str = line[random.randrange(0, len(line))]
|
19 |
+
starting_text: str = re.sub(r"[,:\-–.!;?_]", '', starting_text)
|
20 |
+
print(starting_text)
|
21 |
+
|
22 |
+
response = gpt2_pipe(starting_text, max_length=random.randint(20, 45), num_return_sequences=random.randint(5, 15))
|
23 |
response_list = []
|
24 |
for x in response:
|
25 |
if x['generated_text'].strip() != starting_text:
|
26 |
response_list.append(x['generated_text'])
|
27 |
+
|
28 |
response_end = "\n".join(response_list)
|
29 |
return response_end
|
30 |
|