Kr1shi commited on
Commit
eaac02d
1 Parent(s): 0d70cef
Files changed (2) hide show
  1. app.py +36 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_id = "krishi/tartan2"
10
+ pipe = StableDiffusionPipeline.from_pretrained(model_id).to(device)
11
+
12
+ pipe2 = StableDiffusionImg2ImgPipeline(**pipe.components).to(device)
13
+
14
+ import gradio as gr
15
+
16
+ def generate_txt2img(prompt):
17
+ return pipe(prompt, num_inference_steps=50, guidance_scale=7.5).images[0]
18
+ def generate_img2img(img, prompt):
19
+ image = Image.fromarray(img)
20
+ image = image.resize((512, 512))
21
+ return pipe2(prompt=prompt, image=image, strength=0.75, guidance_scale=7.5).images[0]
22
+
23
+ with gr.Blocks() as demo:
24
+ with gr.Tab("Text2Image"):
25
+ inp_txt = gr.Text(show_label=False, placeholder="Enter your prompt here...")
26
+ btn = gr.Button("Generate")
27
+ out_img = gr.Image()
28
+ btn.click(fn=generate_txt2img, inputs=[inp_txt], outputs=[out_img])
29
+ with gr.Tab("Image2Image"):
30
+ inp_img = gr.Image()
31
+ inp_txt2 = gr.Text(show_label=False, placeholder="Enter your prompt here...")
32
+ btn2 = gr.Button("Generate")
33
+ out_img2 = gr.Image()
34
+ btn2.click(fn=generate_img2img, inputs=[inp_img, inp_txt2], outputs=[out_img2])
35
+
36
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch
2
+ accelerate
3
+ diffusers[torch]
4
+ transformers