Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,7 +26,7 @@ os.makedirs(OUTPUT_DIR, exist_ok=True)
|
|
| 26 |
|
| 27 |
def process(image, progress=gr.Progress()):
|
| 28 |
if image is None:
|
| 29 |
-
return None, None
|
| 30 |
try:
|
| 31 |
progress(0, desc="Starting processing...")
|
| 32 |
orig_image = Image.fromarray(image)
|
|
@@ -74,11 +74,21 @@ def process(image, progress=gr.Progress()):
|
|
| 74 |
output_array = np.array(new_im.convert('RGBA'))
|
| 75 |
|
| 76 |
progress(1.0, desc="Done!")
|
| 77 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
except Exception as e:
|
| 80 |
print(f"Error processing image: {str(e)}")
|
| 81 |
-
return None, None
|
| 82 |
|
| 83 |
css = """
|
| 84 |
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;700&display=swap');
|
|
@@ -182,37 +192,15 @@ with gr.Blocks(css=css) as demo:
|
|
| 182 |
download_button = gr.File(
|
| 183 |
label="Download Processed Image",
|
| 184 |
visible=True,
|
| 185 |
-
elem_classes="download-btn"
|
| 186 |
-
interactive=True
|
| 187 |
)
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
demo.load(None, None, None, _js="""
|
| 191 |
-
function autoDownload() {
|
| 192 |
-
const downloadButtons = document.querySelectorAll('.download-btn button');
|
| 193 |
-
if (downloadButtons.length > 0) {
|
| 194 |
-
downloadButtons[0].click();
|
| 195 |
-
}
|
| 196 |
-
}
|
| 197 |
-
|
| 198 |
-
const observer = new MutationObserver((mutations) => {
|
| 199 |
-
mutations.forEach((mutation) => {
|
| 200 |
-
if (mutation.type === 'childList') {
|
| 201 |
-
const downloadButtons = document.querySelectorAll('.download-btn button');
|
| 202 |
-
if (downloadButtons.length > 0) {
|
| 203 |
-
setTimeout(autoDownload, 1000);
|
| 204 |
-
}
|
| 205 |
-
}
|
| 206 |
-
});
|
| 207 |
-
});
|
| 208 |
-
|
| 209 |
-
observer.observe(document.body, { childList: true, subtree: true });
|
| 210 |
-
""")
|
| 211 |
|
| 212 |
input_image.change(
|
| 213 |
fn=process,
|
| 214 |
inputs=input_image,
|
| 215 |
-
outputs=[output_image, download_button]
|
| 216 |
)
|
| 217 |
|
| 218 |
if __name__ == "__main__":
|
|
|
|
| 26 |
|
| 27 |
def process(image, progress=gr.Progress()):
|
| 28 |
if image is None:
|
| 29 |
+
return None, None, None
|
| 30 |
try:
|
| 31 |
progress(0, desc="Starting processing...")
|
| 32 |
orig_image = Image.fromarray(image)
|
|
|
|
| 74 |
output_array = np.array(new_im.convert('RGBA'))
|
| 75 |
|
| 76 |
progress(1.0, desc="Done!")
|
| 77 |
+
return (
|
| 78 |
+
output_array,
|
| 79 |
+
gr.update(value=filepath, visible=True),
|
| 80 |
+
gr.update(value=f"""
|
| 81 |
+
<script>
|
| 82 |
+
setTimeout(function() {{
|
| 83 |
+
window.location.href = '/file={filepath}';
|
| 84 |
+
}}, 1000);
|
| 85 |
+
</script>
|
| 86 |
+
""")
|
| 87 |
+
)
|
| 88 |
|
| 89 |
except Exception as e:
|
| 90 |
print(f"Error processing image: {str(e)}")
|
| 91 |
+
return None, None, None
|
| 92 |
|
| 93 |
css = """
|
| 94 |
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;500;700&display=swap');
|
|
|
|
| 192 |
download_button = gr.File(
|
| 193 |
label="Download Processed Image",
|
| 194 |
visible=True,
|
| 195 |
+
elem_classes="download-btn"
|
|
|
|
| 196 |
)
|
| 197 |
+
|
| 198 |
+
auto_download = gr.HTML(visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
input_image.change(
|
| 201 |
fn=process,
|
| 202 |
inputs=input_image,
|
| 203 |
+
outputs=[output_image, download_button, auto_download]
|
| 204 |
)
|
| 205 |
|
| 206 |
if __name__ == "__main__":
|