Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import io
|
4 |
+
from diffusers import DiffusionPipeline
|
5 |
+
|
6 |
+
# Load the diffusion pipeline
|
7 |
+
@st.cache_resource
|
8 |
+
def load_pipeline():
|
9 |
+
return DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
|
10 |
+
|
11 |
+
pipe = load_pipeline()
|
12 |
+
|
13 |
+
# Streamlit UI
|
14 |
+
st.title("AI Image to Lego Minifigure Generator")
|
15 |
+
|
16 |
+
st.write("Upload an image to convert it into a Lego minifigure styled image.")
|
17 |
+
|
18 |
+
# File uploader for image upload
|
19 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
20 |
+
|
21 |
+
if uploaded_file is not None:
|
22 |
+
# Read the image
|
23 |
+
input_image = Image.open(uploaded_file)
|
24 |
+
|
25 |
+
# Display the uploaded image
|
26 |
+
st.image(input_image, caption='Uploaded Image', use_column_width=True)
|
27 |
+
|
28 |
+
# Prompt for the transformation
|
29 |
+
prompt = st.text_input("Enter a prompt for the transformation:", "Lego minifigure style")
|
30 |
+
|
31 |
+
if st.button("Generate Image"):
|
32 |
+
if prompt:
|
33 |
+
# Convert the image to bytes
|
34 |
+
buffered = io.BytesIO()
|
35 |
+
input_image.save(buffered, format="PNG")
|
36 |
+
input_image_bytes = buffered.getvalue()
|
37 |
+
|
38 |
+
# Generate the Lego minifigure styled image
|
39 |
+
with st.spinner("Generating image..."):
|
40 |
+
output_image = pipe(prompt).images[0]
|
41 |
+
|
42 |
+
# Display the transformed image
|
43 |
+
st.image(output_image, caption='Generated Lego Minifigure Styled Image', use_column_width=True)
|
44 |
+
else:
|
45 |
+
st.warning("Please enter a prompt for the transformation.")
|
46 |
+
|
47 |
+
# Note: Remember to handle exceptions and edge cases in production code.
|