Commit ·
505d57d
1
Parent(s): f8f5184
Update generate function
Browse files7 unmodified lines89101112131415161718192021222324252627282930313233343536374 unmodified lines42434445464748491 unmodified line515253545556577 unmodified linesdef generate(starting_text):for count in range(4):seed = random.randint(100, 1000000)set_seed(seed)if starting_text == "":starting_text: str = line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize()starting_text: str = re.sub(r"[,:\-–.!;?_]", '', starting_text)print(starting_text)response = gpt2_pipe(starting_text, max_length=(len(starting_text) + random.randint(60, 90)), num_return_sequences=4)response_list = []for x in response:resp = x['generated_text'].strip()if resp != starting_text and len(resp) > (len(starting_text) + 4) and resp.endswith((":", "-", "—")) is False:response_list.append(resp+'\n')response_end = "\n".join(response_list)response_end = re.sub('[^ ]+\.[^ ]+','', response_end)response_end = response_end.replace("<", "").replace(">", "")if response_end != "":return response_endif count == 4:return response_endtxt = grad.Textbox(lines=1, label="Initial Text", placeholder="English Text here")4 unmodified linesexamples.append(line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize())title = "Stable Diffusion Prompt Generator"description = 'This is a demo of the model series: "MagicPrompt", in this case, aimed at: Stable Diffusion. To use it, simply submit your text or click on one of the examples.<b><br><br>To learn more about the model, go to the link: https://huggingface.co/Gustavosta/MagicPrompt-Stable-Diffusion<br>'article = ""grad.Interface(fn=generate,inputs=txt,1 unmodified lineexamples=examples,title=title,description=description,article=article,allow_flagging='never',cache_examples=False,theme="default").launch(enable_queue=True, debug=True)7 unmodified lines891011121314151617181920212223242526272829303132334 unmodified lines383940414243441 unmodified line464748495051527 unmodified linesdef generate(starting_text):seed = random.randint(100, 1000000)set_seed(seed)if starting_text == "":starting_text: str = line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize()starting_text: str = re.sub(r"[,:\-–.!;?_]", '', starting_text)response = gpt2_pipe(starting_text, max_length=(len(starting_text) + random.randint(60, 90)), num_return_sequences=4)response_list = []for x in response:resp = x['generated_text'].strip()if resp != starting_text and len(resp) > (len(starting_text) + 4) and resp.endswith((":", "-", "—")) is False:response_list.append(resp+'\n')response_end = "\n".join(response_list)response_end = re.sub('[^ ]+\.[^ ]+','', response_end)response_end = response_end.replace("<", "").replace(">", "")if response_end != "":return response_endtxt = grad.Textbox(lines=1, label="Initial Text", placeholder="English Text here")4 unmodified linesexamples.append(line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize())title = "Stable Diffusion Prompt Generator"description = 'This is a demo of the model series: "MagicPrompt", in this case, aimed at: "Stable Diffusion". To use it, simply submit your text or click on one of the examples.<br><br>To learn more about the model, [click here]{https://huggingface.co/Gustavosta/MagicPrompt-Stable-Diffusion}.<br>'grad.Interface(fn=generate,inputs=txt,1 unmodified lineexamples=examples,title=title,description=description,article='',allow_flagging='never',cache_examples=False,theme="default").launch(enable_queue=True, debug=True)
app.py+22-27