Silence1412
commited on
Commit
β’
3a7ed92
1
Parent(s):
ec47c3f
Update app.py
Browse files
app.py
CHANGED
@@ -36,25 +36,30 @@ def infer1(starting_text):
|
|
36 |
return response_end
|
37 |
|
38 |
def infer2(starting_text):
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
def infer3(prompt, negative, steps, scale, seed):
|
60 |
generator = torch.Generator(device='cpu').manual_seed(seed)
|
|
|
36 |
return response_end
|
37 |
|
38 |
def infer2(starting_text):
|
39 |
+
for count in range(6):
|
40 |
+
seed = random.randint(100, 1000000)
|
41 |
+
set_seed(seed)
|
42 |
+
|
43 |
+
# If the text field is empty
|
44 |
+
if starting_text == "":
|
45 |
+
starting_text: str = line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize()
|
46 |
+
starting_text: str = re.sub(r"[,:\-β.!;?_]", '', starting_text)
|
47 |
+
print(starting_text)
|
48 |
+
|
49 |
+
response = gpt2_pipe2(starting_text, max_length=random.randint(60, 90), num_return_sequences=8)
|
50 |
+
response_list = []
|
51 |
+
for x in response:
|
52 |
+
resp = x['generated_text'].strip()
|
53 |
+
if resp != starting_text and len(resp) > (len(starting_text) + 4) and resp.endswith((":", "-", "β")) is False:
|
54 |
+
response_list.append(resp)
|
55 |
+
|
56 |
+
response_end = "\n".join(response_list)
|
57 |
+
response_end = re.sub('[^ ]+\.[^ ]+','', response_end)
|
58 |
+
response_end = response_end.replace("<", "").replace(">", "")
|
59 |
+
if response_end != "":
|
60 |
+
return response_end
|
61 |
+
if count == 5:
|
62 |
+
return response_end
|
63 |
|
64 |
def infer3(prompt, negative, steps, scale, seed):
|
65 |
generator = torch.Generator(device='cpu').manual_seed(seed)
|