wifix199's picture
Update app.py
989332d verified
raw
history blame
860 Bytes
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
unet = pipe.unet
def generate_image(prompt, unet):
added_cond_kwargs = {"text_embeds": pipe.get_text_embedding(prompt)}
image = unet(prompt, **added_cond_kwargs).images[0]
return image
def chatbot(prompt):
# Generate the image based on the user's input
image = generate_image(prompt, unet)
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()