File size: 937 Bytes
7467e8a
0b70041
 
9d1b8e4
0b70041
 
 
f6f44a7
 
bffe78e
 
 
 
 
 
0b70041
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
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):
    # Ensure prompt is passed correctly
    inputs = pipe.tokenizer(prompt, return_tensors="pt")
    with torch.no_grad():
        # Ensure inputs are provided correctly
        output = pipe(prompt, **inputs)
    image = output.images[0]
    return image

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()