Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,46 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
from diffusers import DiffusionPipeline
|
|
|
4 |
|
5 |
-
#
|
6 |
@st.cache_resource
|
7 |
-
def
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
# App interface
|
15 |
st.title("Lehenga Dress Image Generator")
|
16 |
st.write("Enter a description to generate an image of a lehenga dress.")
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Input prompt
|
19 |
prompt = st.text_area("Enter your prompt:",
|
20 |
"A flat-lay image of a lehenga with a traditional style and a fitted waistline is elegantly crafted from stretchy silk material, ensuring a comfortable and flattering fit. The long hemline adds a touch of grace and sophistication to the ensemble. Adorned in a solid blue color, it features a sleeveless design that complements its sweetheart neckline. The solid pattern and the luxurious silk fabric together create a timeless and chic look that is perfect for special occasions.")
|
21 |
|
22 |
# Generate button
|
23 |
if st.button("Generate Image"):
|
24 |
-
if
|
|
|
|
|
25 |
with st.spinner("Generating image..."):
|
26 |
try:
|
27 |
# Generate the image
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
from diffusers import DiffusionPipeline
|
4 |
+
import os
|
5 |
|
6 |
+
# Hugging Face Authentication
|
7 |
@st.cache_resource
|
8 |
+
def authenticate_and_load_model(hf_token):
|
9 |
+
"""
|
10 |
+
Authenticate with Hugging Face and load the model.
|
11 |
+
"""
|
12 |
+
os.environ["HF_HOME"] = "./hf_cache" # Set cache directory for Hugging Face models
|
13 |
+
os.environ["HF_AUTH_TOKEN"] = hf_token # Set authentication token for Hugging Face
|
14 |
+
|
15 |
+
try:
|
16 |
+
# Load the model
|
17 |
+
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", use_auth_token=hf_token)
|
18 |
+
pipe.load_lora_weights("tryonlabs/FLUX.1-dev-LoRA-Lehenga-Generator", use_auth_token=hf_token)
|
19 |
+
return pipe
|
20 |
+
except Exception as e:
|
21 |
+
st.error(f"Error loading model: {e}")
|
22 |
+
return None
|
23 |
|
24 |
+
# Streamlit App
|
|
|
|
|
25 |
st.title("Lehenga Dress Image Generator")
|
26 |
st.write("Enter a description to generate an image of a lehenga dress.")
|
27 |
|
28 |
+
# Hugging Face Token Input
|
29 |
+
hf_token = st.text_input("Enter your Hugging Face Token:", type="password")
|
30 |
+
if hf_token:
|
31 |
+
pipe = authenticate_and_load_model(hf_token)
|
32 |
+
else:
|
33 |
+
st.warning("Please enter your Hugging Face token to proceed.")
|
34 |
+
|
35 |
# Input prompt
|
36 |
prompt = st.text_area("Enter your prompt:",
|
37 |
"A flat-lay image of a lehenga with a traditional style and a fitted waistline is elegantly crafted from stretchy silk material, ensuring a comfortable and flattering fit. The long hemline adds a touch of grace and sophistication to the ensemble. Adorned in a solid blue color, it features a sleeveless design that complements its sweetheart neckline. The solid pattern and the luxurious silk fabric together create a timeless and chic look that is perfect for special occasions.")
|
38 |
|
39 |
# Generate button
|
40 |
if st.button("Generate Image"):
|
41 |
+
if not hf_token or not pipe:
|
42 |
+
st.error("Model not loaded. Please ensure you've provided a valid Hugging Face token.")
|
43 |
+
elif prompt.strip():
|
44 |
with st.spinner("Generating image..."):
|
45 |
try:
|
46 |
# Generate the image
|