File size: 1,351 Bytes
d41b29c
495bc09
 
dda71db
3f60c67
cdf4137
495bc09
 
 
735ac07
d41b29c
735ac07
 
 
 
 
 
 
 
 
 
c0e648d
735ac07
 
 
 
 
 
 
 
 
 
 
3b2aa9b
9edf40f
e826dcb
 
 
 
 
 
 
 
 
 
 
e784dcb
 
e826dcb
 
e784dcb
 
 
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
import gradio as gr
import torch as torch
import numpy as np
import sentencepiece
import spaces
import random


from diffusers import DiffusionPipeline
from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast

# gr.load("models/black-forest-labs/FLUX.1-dev").launch()

dtype = torch.bfloat16
device = "cuda" if torch.cuda.is_available() else "cpu"

pipe = DiffusionPipeline.from_pretrained("sayakpaul/FLUX.1-merged", torch_dtype=dtype).to(device)

MAX_SEED = np.iinfo(np.int32).max
MAX_IMAGE_SIZE = 2048

def inferee(prompt, seed=42, randomize_seed=True, width=400, height=400, guidance_scale=3.5, num_inference_steps=8):
    if randomize_seed:
        seed = random.randint(0, MAX_SEED)
    generator = torch.Generator().manual_seed(seed)
    image = pipe(
        prompt = prompt, 
        width = width,
        height = height,
        num_inference_steps = num_inference_steps, 
        generator = generator,
        guidance_scale=guidance_scale
    ).images[0] 
    return image

prompt = gr.Text(
    label="Prompt",
    show_label=False,
    max_lines=1,
    placeholder="Enter your prompt",
    container=False)

run_button = gr.Button("Run", scale=0)

result = gr.Image(label="Result", show_label=False)

interface = gr.Interface(
    fn=inferee,
    inputs=[prompt],
    outputs=[result]
)

interface.launch()