File size: 1,835 Bytes
e33485b
e032f0c
 
fc0f6ae
e032f0c
 
 
 
 
 
 
 
 
 
01d9fff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e032f0c
01d9fff
 
 
e032f0c
 
01d9fff
 
 
 
 
 
 
 
 
 
 
 
 
e032f0c
 
 
 
01d9fff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import gradio as gr
import os

img_to_text = gr.Interface.load("spaces/pharma/CLIP-Interrogator")
stable_diffusion = gr.Blocks.load(name="spaces/stabilityai/stable-diffusion")

def get_images(prompt):
    gallery_dir = stable_diffusion(prompt, fn_index=2)
    return [os.path.join(gallery_dir, image) for image in os.listdir(gallery_dir)]

def get_prompts(uploaded_image):
    return img_to_text(uploaded_image)

with gr.Blocks() as demo:
    gr.Markdown(
        """
        ## Stable Diffusion Perception πŸŽ†πŸŒŒ
        Input an image and see how the model perceives it! πŸ‘€
        """
    )

    with gr.Row():
      with gr.Column():
          input_img = gr.Image(type="filepath")
          with gr.Row():
            see_prompts = gr.Button("Check how your image prompts your model!", elem_id="check_btn_1")              

      with gr.Column():
        img2text_output = gr.Textbox(
                                label="Convert your image to text!", 
                                lines=4,
                                elem_id="translated"
                            )
        with gr.Row():
            diffuse_btn = gr.Button(value="Diffuse it!", elem_id="diffuse_btn")
      with gr.Column():
        sd_output = gr.Gallery().style(grid=2, height="auto")
        
    def translate_directly(img):
        images = get_images(get_prompts(img))
        return images
    see_prompts.click(img_to_text, 
                            inputs = input_img, 
                            outputs = [
                                img2text_output
                            ])
    diffuse_btn.click(get_images, 
                          inputs = [
                              img2text_output
                              ], 
                          outputs = sd_output
                          )



demo.launch()