Spaces:
Runtime error
Runtime error
Update page/reduce.py
Browse files- page/reduce.py +27 -23
page/reduce.py
CHANGED
@@ -3,9 +3,15 @@ from numpy.core.defchararray import lower
|
|
3 |
import streamlit as st
|
4 |
import numpy as np
|
5 |
import pandas as pd
|
6 |
-
|
7 |
import io
|
8 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def dell(ix):
|
11 |
print("!!!!")
|
@@ -18,27 +24,7 @@ def app():
|
|
18 |
|
19 |
st.subheader('Choose which images you would like to remove from your working set.')
|
20 |
|
21 |
-
|
22 |
-
all_files = os.listdir()
|
23 |
-
for f in all_files:
|
24 |
-
os.remove(f)
|
25 |
-
|
26 |
-
# create a ZipFile object
|
27 |
-
zipObj = ZipFile('ai_architecture.zip', 'w')
|
28 |
-
# Add multiple files to the zip
|
29 |
-
for ix,file in enumerate( st.session_state.results ):
|
30 |
-
file['image'].save("temp/"+str(ix)+".jpeg")
|
31 |
-
zipObj.write("temp/"+str(ix)+".jpeg")
|
32 |
-
|
33 |
-
zipObj.close()
|
34 |
-
|
35 |
-
st.download_button(
|
36 |
-
label="Download images as zip",
|
37 |
-
data=open('ai_architecture.zip', 'rb'),
|
38 |
-
file_name='ai_architecture.zip',
|
39 |
-
mime='application/zip'
|
40 |
-
)
|
41 |
-
|
42 |
|
43 |
deleteButtons = []
|
44 |
|
@@ -48,11 +34,29 @@ def app():
|
|
48 |
col1,col2 = st.columns(2)
|
49 |
|
50 |
with col1:
|
51 |
-
st.image(result['image'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
with col2:
|
53 |
st.button("delete ", key=ix, on_click=dell, kwargs=dict(ix=ix) )
|
54 |
|
55 |
m = st.markdown("""
|
56 |
<hr />""", unsafe_allow_html=True)
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
|
|
3 |
import streamlit as st
|
4 |
import numpy as np
|
5 |
import pandas as pd
|
6 |
+
import zipfile
|
7 |
import io
|
8 |
import os
|
9 |
+
from streamlit.elements.image import image_to_url
|
10 |
+
import gzip
|
11 |
+
import requests
|
12 |
+
from io import BytesIO
|
13 |
+
from PIL import Image, ImageDraw
|
14 |
+
import base64
|
15 |
|
16 |
def dell(ix):
|
17 |
print("!!!!")
|
|
|
24 |
|
25 |
st.subheader('Choose which images you would like to remove from your working set.')
|
26 |
|
27 |
+
zipObj = zipfile.ZipFile('ai_architecture.zip', 'w')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
deleteButtons = []
|
30 |
|
|
|
34 |
col1,col2 = st.columns(2)
|
35 |
|
36 |
with col1:
|
37 |
+
t = st.image(result['image'])
|
38 |
+
|
39 |
+
with io.BytesIO() as output:
|
40 |
+
result['image'].save(output, format="JPEG")
|
41 |
+
contents = output.getvalue()
|
42 |
+
|
43 |
+
txt = result['prompt']+" (temperature:"+ str(result['crazy']) + ", top k:" + str(result['k']) + ")"
|
44 |
+
|
45 |
+
zipObj.writestr(txt+".jpg", contents )
|
46 |
+
|
47 |
+
|
48 |
with col2:
|
49 |
st.button("delete ", key=ix, on_click=dell, kwargs=dict(ix=ix) )
|
50 |
|
51 |
m = st.markdown("""
|
52 |
<hr />""", unsafe_allow_html=True)
|
53 |
|
54 |
+
zipObj.close()
|
55 |
+
|
56 |
+
st.download_button(
|
57 |
+
label="Download images as zip",
|
58 |
+
data=open('ai_architecture.zip', 'rb'),
|
59 |
+
file_name='ai_architecture.zip',
|
60 |
+
mime='application/zip'
|
61 |
+
)
|
62 |
|