Silence1412 commited on
Commit
3a7ed92
β€’
1 Parent(s): ec47c3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -19
app.py CHANGED
@@ -36,25 +36,30 @@ def infer1(starting_text):
36
  return response_end
37
 
38
  def infer2(starting_text):
39
- seed = random.randint(100, 1000000)
40
- set_seed(seed)
41
-
42
- if starting_text == "":
43
- starting_text: str = re.sub(r"[,:\-–.!;?_]", '', starting_text)
44
-
45
- response = gpt2_pipe2(starting_text, max_length=(len(starting_text) + random.randint(60, 90)), num_return_sequences=4)
46
- response_list = []
47
- for x in response:
48
- resp = x['generated_text'].strip()
49
- if resp != starting_text and len(resp) > (len(starting_text) + 4) and resp.endswith((":", "-", "β€”")) is False:
50
- response_list.append(resp+'\n')
51
-
52
- response_end = "\n".join(response_list)
53
- response_end = re.sub('[^ ]+\.[^ ]+','', response_end)
54
- response_end = response_end.replace("<", "").replace(">", "")
55
-
56
- if response_end != "":
57
- return response_end
 
 
 
 
 
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)