Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from diffusers import DiffusionPipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
# Load the diffusion pipeline model
|
| 7 |
+
@st.cache_resource
|
| 8 |
+
def load_pipeline():
|
| 9 |
+
pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
|
| 10 |
+
pipe.load_lora_weights("Melonie/text_to_image_finetuned")
|
| 11 |
+
return pipe
|
| 12 |
+
|
| 13 |
+
pipe = load_pipeline()
|
| 14 |
+
|
| 15 |
+
# Streamlit app
|
| 16 |
+
st.title("Text-to-Image Generation App")
|
| 17 |
+
|
| 18 |
+
# User input for prompt
|
| 19 |
+
user_prompt = st.text_input("Enter your image prompt", value="Astronaut in a jungle, cold color palette, muted colors, detailed, 8k")
|
| 20 |
+
|
| 21 |
+
# Button to generate the image
|
| 22 |
+
if st.button("Generate Image"):
|
| 23 |
+
if user_prompt:
|
| 24 |
+
with st.spinner("Generating image..."):
|
| 25 |
+
# Generate the image
|
| 26 |
+
image = pipe(user_prompt).images[0]
|
| 27 |
+
|
| 28 |
+
# Display the generated image
|
| 29 |
+
st.image(image, caption="Generated Image", use_column_width=True)
|
| 30 |
+
else:
|
| 31 |
+
st.error("Please enter a valid prompt.")
|