Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,24 +10,28 @@ with open("name.txt", "r") as f:
|
|
10 |
|
11 |
|
12 |
def generate(starting_text):
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
starting_text
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
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")
|