Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -60,7 +60,18 @@ if TORCH_COMPILE:
|
|
60 |
pipe.load_lora_weights("latent-consistency/lcm-lora-sdv1-5")
|
61 |
pipe.fuse_lora()
|
62 |
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
def predict(prompt, guidance, steps, seed=1231231):
|
65 |
generator = torch.manual_seed(seed)
|
66 |
last_time = time.time()
|
@@ -93,15 +104,12 @@ def predict(prompt, guidance, steps, seed=1231231):
|
|
93 |
image_path = os.path.join("", filename) # Specify your directory
|
94 |
results.images[0].save(image_path)
|
95 |
print(f"#Image saved as {image_path}")
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
-
# Create a download link
|
98 |
-
with open(image_path, "rb") as file:
|
99 |
-
btn = st.download_button(
|
100 |
-
label="Download 📥",
|
101 |
-
data=file,
|
102 |
-
file_name=filename,
|
103 |
-
mime="image/png"
|
104 |
-
)
|
105 |
|
106 |
return results.images[0] if len(results.images) > 0 else None
|
107 |
|
|
|
60 |
pipe.load_lora_weights("latent-consistency/lcm-lora-sdv1-5")
|
61 |
pipe.fuse_lora()
|
62 |
|
63 |
+
def safe_filename(text):
|
64 |
+
"""Generate a safe filename from a string."""
|
65 |
+
safe_text = re.sub(r'\W+', '_', text)
|
66 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
67 |
+
return f"{safe_text}_{timestamp}.png"
|
68 |
+
|
69 |
+
def encode_image(image):
|
70 |
+
"""Encode image to base64."""
|
71 |
+
buffered = BytesIO()
|
72 |
+
image.save(buffered, format="PNG")
|
73 |
+
return base64.b64encode(buffered.getvalue()).decode()
|
74 |
+
|
75 |
def predict(prompt, guidance, steps, seed=1231231):
|
76 |
generator = torch.manual_seed(seed)
|
77 |
last_time = time.time()
|
|
|
104 |
image_path = os.path.join("", filename) # Specify your directory
|
105 |
results.images[0].save(image_path)
|
106 |
print(f"#Image saved as {image_path}")
|
107 |
+
filename = safe_filename(prompt)
|
108 |
+
image.save(filename)
|
109 |
+
encoded_image = encode_image(image)
|
110 |
+
html_link = f'<a href="data:image/png;base64,{encoded_image}" download="{filename}">Download Image</a>'
|
111 |
+
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
return results.images[0] if len(results.images) > 0 else None
|
115 |
|