Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,16 @@ import torch
|
|
| 4 |
from langs import LANGS
|
| 5 |
import os
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
pipe1 = pipeline('text-generation', model='RamAnanth1/distilgpt2-sd-prompts')
|
| 8 |
|
| 9 |
TASK = "translation"
|
|
@@ -54,6 +64,14 @@ def infer(input):
|
|
| 54 |
result = get_new_prompt(img, 'fast')
|
| 55 |
return result[0]
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
with gr.Blocks() as demo:
|
| 58 |
gr.Markdown(
|
| 59 |
""" # <center>🥳💬💕 - Stable Diffusion,随时随地,想画就画!</center>
|
|
@@ -73,14 +91,27 @@ with gr.Blocks() as demo:
|
|
| 73 |
with gr.Row().style(equal_height=True):
|
| 74 |
inp2 = out1
|
| 75 |
btn1 = gr.Button("让您的提示词更详细一些吧")
|
| 76 |
-
out2 = gr.Textbox(label = "
|
| 77 |
|
| 78 |
btn1.click(infer, [inp2], [out2])
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
gr.Markdown(
|
| 81 |
""" ### <center>注意❗:请不要输入或生成会对个人以及组织造成侵害的内容,此程序仅供科研、学习及娱乐使用。用户输入或生成的内容与程序开发者无关,请自觉合法合规使用,违反者一切后果自负。</center>
|
| 82 |
|
| 83 |
-
### <center>Model by [
|
| 84 |
|
| 85 |
"""
|
| 86 |
)
|
|
|
|
| 4 |
from langs import LANGS
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
import numpy as np
|
| 8 |
+
import modin.pandas as pd
|
| 9 |
+
from PIL import Image
|
| 10 |
+
from diffusers import DiffusionPipeline #EulerDiscreteScheduler
|
| 11 |
+
|
| 12 |
+
device1 = "cuda" if torch.cuda.is_available() else "cpu"
|
| 13 |
+
|
| 14 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", safety_checker=None)
|
| 15 |
+
pipe = pipe.to(device1)
|
| 16 |
+
|
| 17 |
pipe1 = pipeline('text-generation', model='RamAnanth1/distilgpt2-sd-prompts')
|
| 18 |
|
| 19 |
TASK = "translation"
|
|
|
|
| 64 |
result = get_new_prompt(img, 'fast')
|
| 65 |
return result[0]
|
| 66 |
|
| 67 |
+
#stable diffusion
|
| 68 |
+
|
| 69 |
+
def genie (prompt, negative_prompt, scale, steps, seed):
|
| 70 |
+
generator = torch.Generator(device=device1).manual_seed(seed)
|
| 71 |
+
images = pipe(prompt, negative_prompt=negative_prompt, width=768, height=768, num_inference_steps=steps, guidance_scale=scale, num_images_per_prompt=1, generator=generator).images[0]
|
| 72 |
+
return images
|
| 73 |
+
|
| 74 |
+
|
| 75 |
with gr.Blocks() as demo:
|
| 76 |
gr.Markdown(
|
| 77 |
""" # <center>🥳💬💕 - Stable Diffusion,随时随地,想画就画!</center>
|
|
|
|
| 91 |
with gr.Row().style(equal_height=True):
|
| 92 |
inp2 = out1
|
| 93 |
btn1 = gr.Button("让您的提示词更详细一些吧")
|
| 94 |
+
out2 = gr.Textbox(label = "更详细的提示词(可在此编辑)", lines=1)
|
| 95 |
|
| 96 |
btn1.click(infer, [inp2], [out2])
|
| 97 |
+
|
| 98 |
+
with gr.Row().style(equal_height=True):
|
| 99 |
+
inp3 = out2
|
| 100 |
+
inp4 = gr.Textbox(label="删去一些您不想要的特点(反向关键词;选填)", placeholder = "low quality", lines=1)
|
| 101 |
+
inp5 = gr.Slider(1, 25, 10)
|
| 102 |
+
inp6 = gr.Slider(30, maximum=75, value=50, step=1)
|
| 103 |
+
inp7 = gr.Slider(minimum=1, step=1, maximum=999999999999999999, randomize=True)
|
| 104 |
+
|
| 105 |
+
with gr.Row().style(equal_height=True):
|
| 106 |
+
btn2 = gr.Button("开始生成图片吧")
|
| 107 |
+
out3 = gr.Image(label="为您生成的专属图片")
|
| 108 |
+
|
| 109 |
+
btn2.click(genie, [inp3, inp4, inp5, inp6, inp7], [out3])
|
| 110 |
+
|
| 111 |
gr.Markdown(
|
| 112 |
""" ### <center>注意❗:请不要输入或生成会对个人以及组织造成侵害的内容,此程序仅供科研、学习及娱乐使用。用户输入或生成的内容与程序开发者无关,请自觉合法合规使用,违反者一切后果自负。</center>
|
| 113 |
|
| 114 |
+
### <center>Model by [Stable Diffusion](https://github.com/Stability-AI/stablediffusion). Thanks to [Manjushri](https://huggingface.co/Manjushri).</center>
|
| 115 |
|
| 116 |
"""
|
| 117 |
)
|