Spaces:
Runtime error
Runtime error
File size: 1,250 Bytes
52fe0a9 6ab762d 52fe0a9 6ab762d 52fe0a9 6ab762d |
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 |
import streamlit as st
import torch
from diffusers import StableDiffusionPipeline
model_id1 = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionPipeline.from_pretrained(model_id1, torch_dtype=torch.float16, use_safetensors=True)
pipe = pipe.to("cuda")
def generate_image(prompt, negative_prompt, num_inference_steps=50, width=640):
params = {
'prompt': prompt,
'num_inference_steps': num_inference_steps,
'num_images_per_prompt': 2,
'height': int(1.2 * width),
'width': width,
'negative_prompt': negative_prompt
}
img = pipe(**params).images
return img[0], img[1]
def main():
st.title("Diffuser Image Generator")
prompt = st.text_input("Enter the prompt:")
negative_prompt = st.text_input("Enter the negative prompt:")
num_inference_steps = st.slider("Number of inference steps", 1, 100, 50)
width = st.slider("Width", 512, 640, 640)
if st.button("Generate Image"):
image1, image2 = generate_image(prompt, negative_prompt, num_inference_steps, width)
st.image(image1, caption="Generated Image 1", use_column_width=True)
st.image(image2, caption="Generated Image 2", use_column_width=True)
if __name__ == "__main__":
main() |