doevent commited on
Commit
875c380
1 Parent(s): 4b8a685

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -18
app.py CHANGED
@@ -10,24 +10,28 @@ with open("name.txt", "r") as f:
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))].replace("\n", "").lower().capitalize()
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
- resp = x['generated_text'].strip()
26
- if resp != starting_text and len(resp) > (len(starting_text) + 4) and resp.endswith((":", "-", "—")) is False:
27
- response_list.append(resp)
28
-
29
- response_end = "\n".join(response_list)
30
- return response_end
 
 
 
 
31
 
32
 
33
  txt = grad.Textbox(lines=1, label="English", placeholder="English Text here")
 
10
 
11
 
12
  def generate(starting_text):
13
+ for count in range(6):
14
+ seed = random.randint(100, 1000000)
15
+ set_seed(seed)
16
+
17
+ # If the text field is empty
18
+ if starting_text == "":
19
+ starting_text: str = line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize()
20
+ starting_text: str = re.sub(r"[,:\-–.!;?_]", '', starting_text)
21
+ print(starting_text)
22
+
23
+ response = gpt2_pipe(starting_text, max_length=random.randint(20, 45), num_return_sequences=random.randint(5, 15))
24
+ response_list = []
25
+ for x in response:
26
+ resp = x['generated_text'].strip()
27
+ if resp != starting_text and len(resp) > (len(starting_text) + 4) and resp.endswith((":", "-", "—")) is False:
28
+ response_list.append(resp)
29
+
30
+ response_end = "\n".join(response_list)
31
+ if response_end != "":
32
+ return response_end
33
+ if count == 5:
34
+ return response_end
35
 
36
 
37
  txt = grad.Textbox(lines=1, label="English", placeholder="English Text here")