File size: 1,219 Bytes
2e7631c
 
 
 
a06397b
4b90f3d
2e7631c
0f4f141
5d517d3
2e7631c
 
 
fd98974
2e7631c
 
 
 
 
 
 
 
 
b025b10
2e7631c
a06397b
5019a97
a06397b
 
 
2e7631c
5d517d3
 
5019a97
 
5d517d3
2e7631c
5d517d3
2e7631c
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
from diffusers import StableDiffusionPipeline, DiffusionPipeline
import torch
import random
from datetime import datetime
import time
import gradio as gr
from PIL import Image

resolution = (512, 512)  # Risoluzione dell'immagine (width, height)
num_steps = 20
guidance_scale = 7.5
neg_prompt = "blurry"

model_id = "stablediffusionapi/duchaiten-real3d-nsfw-xl"
pipe = DiffusionPipeline.from_pretrained(model_id)

# Imposta il dispositivo su GPU se disponibile
device = "cuda" if torch.cuda.is_available() else "cpu"
pipe = pipe.to(device)


# Funzione per generare un'immagine
def generate_image(prompt, neg_prompt, width=resolution[0], height=resolution[1], seed=1, steps=35):
    generator = torch.manual_seed(seed)
    start_time = time.time()
    image = pipe(prompt, height=height, width=width, num_inference_steps=steps, guidance_scale=guidance_scale, generator=generator, negative_prompt=neg_prompt).images[0]
    end_time = time.time()    
    elapsed_time = end_time - start_time
    return image, elapsed_time

demo = gr.Interface(
    fn=generate_image,
    inputs=["text","text","number","number", "slider", "slider"],
    outputs=[gr.Image(),gr.Textbox(label="Elapsed time (seconds)")],
)

demo.launch()