Spaces:
Running
Running
File size: 1,977 Bytes
7467e8a 0b70041 9d1b8e4 0b70041 f6f44a7 606bbe6 bffe78e 0b70041 f6f44a7 d709633 0b70041 d709633 f6f44a7 0b70041 |
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 |
import torch
from diffusers import StableDiffusionPipeline
import gradio as gr
model_id = "SG161222/RealVisXL_V4.0"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe.to("cpu") # Use "cuda" if GPU is available
def generate_image(
prompt: str,
negative_prompt: str = "",
use_negative_prompt: bool = False,
style: str = DEFAULT_STYLE_NAME,
seed: int = 0,
width: int = 1024,
height: int = 1024,
guidance_scale: float = 3,
randomize_seed: bool = False,
use_resolution_binning: bool = True,
progress=gr.Progress(track_tqdm=True),
):
if check_text(prompt, negative_prompt):
raise ValueError("Prompt contains restricted words.")
prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
seed = int(randomize_seed_fn(seed, randomize_seed))
generator = torch.Generator().manual_seed(seed)
if not use_negative_prompt:
negative_prompt = "" # type: ignore
negative_prompt += default_negative
options = {
"prompt": prompt,
"negative_prompt": negative_prompt,
"width": width,
"height": height,
"guidance_scale": guidance_scale,
"num_inference_steps": 25,
"generator": generator,
"num_images_per_prompt": NUM_IMAGES_PER_PROMPT,
"use_resolution_binning": use_resolution_binning,
"output_type": "pil",
}
images = pipe(**options).images + pipe2(**options).images
image_paths = [save_image(img) for img in images]
return image_paths, seed
def chatbot(prompt):
# Generate the image based on the user's input
image = generate_image(prompt)
return image
# Create the Gradio interface
interface = gr.Interface(
fn=chatbot,
inputs="text",
outputs="image",
title="RealVisXL V4.0 Text-to-Image Chatbot",
description="Enter a text prompt and get an AI-generated image."
)
# Launch the interface
interface.launch()
|