Spaces:
Running
Running
salomonsky
commited on
Commit
•
deefb5c
1
Parent(s):
b2a8d42
Update app.py
Browse files
app.py
CHANGED
@@ -41,23 +41,6 @@ async def gen(prompts, width, height, model_name, num_variants=1, use_enhanced=T
|
|
41 |
def list_saved_images():
|
42 |
return sorted(DATA_PATH.glob("*.jpg"), key=os.path.getmtime, reverse=True)
|
43 |
|
44 |
-
def display_gallery():
|
45 |
-
images = list_saved_images()
|
46 |
-
if images:
|
47 |
-
cols = st.columns(8)
|
48 |
-
for i, image_file in enumerate(images):
|
49 |
-
with cols[i % 8]:
|
50 |
-
st.image(str(image_file), caption=image_file.name, use_column_width=True)
|
51 |
-
prompt = get_prompt_for_image(image_file.name)
|
52 |
-
st.write(prompt[:300])
|
53 |
-
|
54 |
-
if st.button(f"Borrar", key=f"delete_{i}_{image_file.name}"):
|
55 |
-
os.remove(image_file)
|
56 |
-
st.success("Imagen borrada")
|
57 |
-
display_gallery()
|
58 |
-
else:
|
59 |
-
st.info("No hay imágenes guardadas.")
|
60 |
-
|
61 |
def save_prompt(prompt):
|
62 |
with open(DATA_PATH / "prompts.txt", "a") as f:
|
63 |
f.write(prompt + "\n")
|
@@ -133,6 +116,26 @@ async def generate_variations(prompt, num_variants, use_enhanced, style):
|
|
133 |
prompts.add(f"{prompt}, estilo: {style}")
|
134 |
return list(prompts)
|
135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
async def main():
|
137 |
st.set_page_config(layout="wide")
|
138 |
|
@@ -170,8 +173,7 @@ async def main():
|
|
170 |
except Exception as e:
|
171 |
st.error(f"Error al generar las imágenes: {str(e)}")
|
172 |
|
173 |
-
|
174 |
-
|
175 |
|
176 |
if __name__ == "__main__":
|
177 |
asyncio.run(main())
|
|
|
41 |
def list_saved_images():
|
42 |
return sorted(DATA_PATH.glob("*.jpg"), key=os.path.getmtime, reverse=True)
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
def save_prompt(prompt):
|
45 |
with open(DATA_PATH / "prompts.txt", "a") as f:
|
46 |
f.write(prompt + "\n")
|
|
|
116 |
prompts.add(f"{prompt}, estilo: {style}")
|
117 |
return list(prompts)
|
118 |
|
119 |
+
def image_viewer():
|
120 |
+
images = list_saved_images()
|
121 |
+
if images:
|
122 |
+
if 'current_image_index' not in st.session_state:
|
123 |
+
st.session_state['current_image_index'] = 0
|
124 |
+
|
125 |
+
current_index = st.session_state['current_image_index']
|
126 |
+
image_file = images[current_index]
|
127 |
+
st.image(str(image_file), use_column_width=True, caption=image_file.name)
|
128 |
+
|
129 |
+
col1, col2, col3 = st.columns([1, 2, 1])
|
130 |
+
with col1:
|
131 |
+
if st.button("⬅️", key="prev_image"):
|
132 |
+
st.session_state['current_image_index'] = (current_index - 1) % len(images)
|
133 |
+
with col3:
|
134 |
+
if st.button("➡️", key="next_image"):
|
135 |
+
st.session_state['current_image_index'] = (current_index + 1) % len(images)
|
136 |
+
else:
|
137 |
+
st.info("No hay imágenes guardadas.")
|
138 |
+
|
139 |
async def main():
|
140 |
st.set_page_config(layout="wide")
|
141 |
|
|
|
173 |
except Exception as e:
|
174 |
st.error(f"Error al generar las imágenes: {str(e)}")
|
175 |
|
176 |
+
image_viewer()
|
|
|
177 |
|
178 |
if __name__ == "__main__":
|
179 |
asyncio.run(main())
|