File size: 3,606 Bytes
59f949f
 
 
 
 
 
 
 
 
 
053ae38
 
 
59f949f
 
 
053ae38
 
 
 
 
 
 
59f949f
053ae38
 
59f949f
053ae38
59f949f
 
053ae38
59f949f
 
 
053ae38
 
 
59f949f
 
 
 
053ae38
59f949f
 
053ae38
59f949f
053ae38
59f949f
 
053ae38
59f949f
053ae38
59f949f
 
 
053ae38
59f949f
 
053ae38
59f949f
 
 
 
 
 
 
 
 
053ae38
59f949f
 
053ae38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59f949f
 
 
 
 
 
 
 
 
053ae38
59f949f
 
3b8fed9
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from __future__ import annotations

import gradio as gr
import spaces
from PIL import Image
import torch

from my_run import run as run_model


DESCRIPTION = """# Turbo Edit
"""


@spaces.GPU
def main_pipeline(
    input_image: str,
    src_prompt: str,
    tgt_prompt: str,
    seed: int,
    w1: float,
    # w2: float,
):

    w2 = 1.0
    res_image = run_model(input_image, src_prompt, tgt_prompt, seed, w1, w2)

    return res_image


with gr.Blocks(css="app/style.css") as demo:
    gr.Markdown(DESCRIPTION)

    gr.HTML(
        """<a href="https://huggingface.co/spaces/turboedit/turbo_edit?duplicate=true">
        <img src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>Duplicate the Space to run privately without waiting in queue"""
    )

    with gr.Row():
        with gr.Column():
            input_image = gr.Image(
                label="Input image", type="filepath", height=512, width=512
            )
            src_prompt = gr.Text(
                label="Source Prompt",
                max_lines=1,
                placeholder="Source Prompt",
            )
            tgt_prompt = gr.Text(
                label="Target Prompt",
                max_lines=1,
                placeholder="Target Prompt",
            )
            with gr.Accordion("Advanced Options", open=False):
                seed = gr.Slider(
                    label="seed", minimum=0, maximum=16 * 1024, value=7865, step=1
                )
                w1 = gr.Slider(
                    label="w", minimum=1.0, maximum=3.0, value=1.5, step=0.05
                )
                # w2 = gr.Slider(
                #     label='w2',
                #     minimum=1.0,
                #     maximum=3.0,
                #     value=1.0,
                #     step=0.05
                # )

            run_button = gr.Button("Edit")
        with gr.Column():
            # result = gr.Gallery(label='Result')
            result = gr.Image(label="Result", type="pil", height=512, width=512)

            # examples = [
            #     [
            #         "demo_im/WhatsApp Image 2024-05-17 at 17.32.53.jpeg", #input_image
            #         "a painting of a white cat sleeping on a lotus flower", #src_prompt
            #         "a painting of a white cat sleeping on a lotus flower", #tgt_prompt
            #         4759, #seed
            #         1.0, #w1
            #         # 1.1, #w2
            #     ],
            #     [
            #         "demo_im/pexels-pixabay-458976.less.png", #input_image
            #         "a squirrel standing in the grass", #src_prompt
            #         "a squirrel standing in the grass", #tgt_prompt
            #         6128, #seed
            #         1.25, #w1
            #         # 1.1, #w2
            #     ],
            # ]

            # gr.Examples(examples=examples,
            #             inputs=[
            #                 input_image,
            #                 src_prompt,
            #                 tgt_prompt,
            #                 seed,
            #                 w1,
            #                 # w2,
            #             ],
            #             outputs=[
            #                 result
            #             ],
            #             fn=main_pipeline,
            #             cache_examples=True)

    inputs = [
        input_image,
        src_prompt,
        tgt_prompt,
        seed,
        w1,
        # w2,
    ]
    outputs = [result]
    run_button.click(fn=main_pipeline, inputs=inputs, outputs=outputs)

demo.queue(max_size=50).launch(share=False)