File size: 902 Bytes
7467e8a
0b70041
 
9d1b8e4
bcd5c1c
 
 
 
f6f44a7
b32f8d8
bcd5c1c
1f38b4a
cc63412
63cbc5c
5d4cc61
 
b32f8d8
f6f44a7
9614ae1
0b70041
 
 
 
 
bcd5c1c
0b70041
d709633
f6f44a7
0b70041
b32f8d8
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
import torch
from diffusers import StableDiffusionPipeline
import gradio as gr

# Use the CompVis stable-diffusion-v1-4 model
model_id = "CompVis/stable-diffusion-v1-4"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)  # float32 for CPU
pipe.to("cpu")  # Ensure it runs on CPU

def generate_image(prompt, pipe):
    # Generate the image using the pipeline
    image = pipe(prompt, guidance_scale=7.5, num_inference_steps=50).images[0]
    return image

def chatbot(prompt):
    # Generate the image based on the user's input
    image = generate_image(prompt, pipe)
    return image

# Create the Gradio interface
interface = gr.Interface(
    fn=chatbot,
    inputs="text",
    outputs="image",
    title="Stable Diffusion v1-4 Text-to-Image Chatbot",
    description="Enter a text prompt and get an AI-generated image."
)

# Launch the interface
interface.launch()