Spaces:
Runtime error
Runtime error
add app.py
Browse files- app.py +38 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import StableDiffusionPipeline
|
2 |
+
import torch
|
3 |
+
import requests
|
4 |
+
from PIL import Image
|
5 |
+
from io import BytesIO
|
6 |
+
from diffusers import StableDiffusionImg2ImgPipeline
|
7 |
+
|
8 |
+
device = "cpu"
|
9 |
+
#model_path = "weights"
|
10 |
+
#model_id_or_path = "runwayml/stable-diffusion-v1-5"
|
11 |
+
|
12 |
+
model_id = "rikdas/weights"
|
13 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id).to(device)
|
14 |
+
|
15 |
+
pipe2 = StableDiffusionImg2ImgPipeline.from_pretrained(model_id).to(device)
|
16 |
+
|
17 |
+
import gradio as gr
|
18 |
+
|
19 |
+
def generate_txt2img(prompt):
|
20 |
+
return pipe(prompt, num_inference_steps=25, guidance_scale=7.5).images[0]
|
21 |
+
def generate_img2img(img, prompt):
|
22 |
+
image = Image.fromarray(img)
|
23 |
+
return pipe2(prompt=prompt, image=image, strength=0.75, guidance_scale=7.5).images[0]
|
24 |
+
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
with gr.Tab("Text2Image"):
|
27 |
+
inp_txt = gr.Text(showlabel=False, placeholder="Enter your prompt here...")
|
28 |
+
btn = gr.Button("Generate")
|
29 |
+
out_img = gr.Image()
|
30 |
+
btn.click(fn=generate_txt2img, inputs=[inp_txt], outputs=[out_img])
|
31 |
+
with gr.Tab("Image2Image"):
|
32 |
+
inp_img = gr.Image()
|
33 |
+
inp_txt2 = gr.Text(showlabel=False,placeholder="Enter your prompt here...")
|
34 |
+
btn2 = gr.Button("Generate")
|
35 |
+
out_img2 = gr.Image()
|
36 |
+
btn2.click(fn=generate_img2img, inputs=[inp_img, inp_txt2], outputs=[out_img2])
|
37 |
+
|
38 |
+
demo.launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
accelerate
|
3 |
+
diffusers[torch]
|
4 |
+
transformers
|