import streamlit as st from PIL import Image import requests from io import BytesIO # import tensorflow as tf import streamlit as st from diffusers import StableDiffusionPipeline import torch from accelerate import Accelerator #model_id = "CompVis/stable-diffusion-v1-4" #pipe = StableDiffusionPipeline.from_pretrained(model_id) # Ensure the model is using the CPU #pipe = pipe.to("cpu") image_html = "" accelerator = Accelerator() # Function to display an example image def display_example_image(url): response = requests.get(url) img = Image.open(BytesIO(response.content)) st.image(img, caption='Generated Image', use_column_width=True) #function to generate AI based images using Huggingface Diffusers def generate_images_using_huggingface_diffusers(text): # pipe = StableDiffusionPipeline.from_pretrained("sd-dreambooth-library/cat-toy", torch_dtype=torch.float16) pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float32) # pipe = pipe.to("cuda") pipe = pipe.to(accelerator.device) prompt = text image = pipe(prompt,num_images_per_prompt=3) return image # Placeholder function for generating images (replace this with your actual generative AI code) def generate_images(prompt, num_images=3): # This is a placeholder function. Replace it with your actual image generation code. # Here, we are just returning the same example image multiple times for demonstration. image_url = pipe(prompt, num_images_per_prompt=num_samples, num_inference_steps=50, guidance_scale=7.5).images # Replace with a valid image URL response = requests.get(image_url) img = Image.open(BytesIO(response.content)) image_html = image_url return [img] * num_images title_center = """ """ # Title of the app st.markdown(title_center, unsafe_allow_html=True) title_container = """

AutoFloor

""" st.markdown(title_container, unsafe_allow_html=True) # Text input for user prompt user_prompt = st.text_input("Enter your prompt here:") # file= st.file_uploader ("Unggah file Gambar", type = ["jpg", "png"]) # model = tf.keras.models.load_model('L00005_HL512_bagus.h5') st.markdown(""" """, unsafe_allow_html=True) st.markdown('', unsafe_allow_html=True) # Generate and display images in a 3x3 grid if st.button('Generate Images', type="primary"): if user_prompt: st.write(f"Prompt: {user_prompt}") #image_url = "https://wpmedia.roomsketcher.com/content/uploads/2022/01/06145940/What-is-a-floor-plan-with-dimensions.png" # Replace with a valid image URL # Generate images based on the user's prompt #generated_images = generate_images(user_prompt, num_images=3) image_output = generate_images_using_huggingface_diffusers(user_prompt) st.info("Generating image.....") st.success("Image Generated Successfully") st.image(image_output, caption="Generated by Huggingface Diffusers") html_code = f"""
Zoomable Image
""" # # Embed the HTML and JavaScript into the Streamlit app # st.components.v1.html(html_code, height=300) # Display images in a 3x3 grid cols = st.columns(3) for i in range(3): # for j in range(3): # with cols[j]: # st.image(generated_images[i * 3 + j], use_column_width=True) # Display the image with zoom effect # container_style = """ #
# #
# """.format(image_url) # st.markdown(container_style, unsafe_allow_html=True) st.components.v1.html(html_code, height=600) else: st.write("Please enter a prompt.")