Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,9 +5,17 @@ import numpy as np
|
|
5 |
from math import cos, radians, sin
|
6 |
import os
|
7 |
import time
|
|
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def preprocess_image(image):
|
13 |
# Ensure the image is square by padding it
|
@@ -103,12 +111,17 @@ def create_gif(editor1_output, editor2_output, transition_type):
|
|
103 |
with open(output_path, "wb") as f:
|
104 |
f.write(output.getvalue())
|
105 |
|
106 |
-
#
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
# Return the updated list of generated GIFs
|
111 |
-
return
|
112 |
|
113 |
except Exception as e:
|
114 |
raise ValueError(f"Error creating GIF: {e}")
|
@@ -162,5 +175,8 @@ with gr.Blocks() as iface:
|
|
162 |
outputs=[output_gallery]
|
163 |
)
|
164 |
|
|
|
|
|
|
|
165 |
# Launch the interface
|
166 |
iface.launch(share=True)
|
|
|
5 |
from math import cos, radians, sin
|
6 |
import os
|
7 |
import time
|
8 |
+
import json
|
9 |
|
10 |
+
def load_history():
|
11 |
+
try:
|
12 |
+
history = gr.get_state("generated_gifs")
|
13 |
+
return json.loads(history) if history else []
|
14 |
+
except:
|
15 |
+
return []
|
16 |
+
|
17 |
+
def save_history(history):
|
18 |
+
gr.set_state("generated_gifs", json.dumps(history))
|
19 |
|
20 |
def preprocess_image(image):
|
21 |
# Ensure the image is square by padding it
|
|
|
111 |
with open(output_path, "wb") as f:
|
112 |
f.write(output.getvalue())
|
113 |
|
114 |
+
# Load existing history
|
115 |
+
history = load_history()
|
116 |
+
|
117 |
+
# Add the new GIF to the history
|
118 |
+
history.append((output_path, f"{transition_type.capitalize()} transition"))
|
119 |
+
|
120 |
+
# Save updated history
|
121 |
+
save_history(history)
|
122 |
|
123 |
# Return the updated list of generated GIFs
|
124 |
+
return history
|
125 |
|
126 |
except Exception as e:
|
127 |
raise ValueError(f"Error creating GIF: {e}")
|
|
|
175 |
outputs=[output_gallery]
|
176 |
)
|
177 |
|
178 |
+
# Load initial history when the app starts
|
179 |
+
iface.load(lambda: gr.update(value=load_history()), outputs=[output_gallery])
|
180 |
+
|
181 |
# Launch the interface
|
182 |
iface.launch(share=True)
|