Owos commited on
Commit
2bb77de
·
1 Parent(s): 8e08865

added keep styling and image saving

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -24,7 +24,7 @@ st.sidebar.markdown('<p class="font">Afrodreams.AI</p>', unsafe_allow_html=True)
24
  with st.sidebar.expander("About the App"):
25
  st.write("""
26
  This app takes in your image and styles it with a unique african art.""")
27
- style_weight = st.slider("Select Style Weight)
28
 
29
  #Add file uploader to allow users to upload photos
30
  uploaded_file = st.file_uploader("", type=['jpg','png','jpeg'])
@@ -49,12 +49,14 @@ if uploaded_file is not None:
49
  params.backend = "mkl"
50
  params.image_size = 300
51
  params.content_image = uploaded_file
52
- path = 'stylesv2'
53
- styles = os.listdir(path)
54
- params.style_weight = 12
55
  params.style_image = path + '/' + random.choice(styles)
56
-
57
  if run==True:
 
 
 
 
 
58
  st.session_state.submitted = True
59
  my_bar.progress(neural_style.transfer(params))
60
 
@@ -64,9 +66,14 @@ if uploaded_file is not None:
64
  result = Image.open('out.png')
65
  st.image(result, width=500)
66
  buf = BytesIO()
67
- result.save(buf, format="JPEG")
 
 
68
  byte_im = buf.getvalue()
69
  run =st.download_button(label="Download Image", data=byte_im, file_name='afrodreams.jpg', mime="image/png")
 
 
 
70
 
71
 
72
 
 
24
  with st.sidebar.expander("About the App"):
25
  st.write("""
26
  This app takes in your image and styles it with a unique african art.""")
27
+ style_weight = st.slider("Select Style Weight", min_value=10, max_value=100, value=12)
28
 
29
  #Add file uploader to allow users to upload photos
30
  uploaded_file = st.file_uploader("", type=['jpg','png','jpeg'])
 
49
  params.backend = "mkl"
50
  params.image_size = 300
51
  params.content_image = uploaded_file
 
 
 
52
  params.style_image = path + '/' + random.choice(styles)
53
+ keep_style = False
54
  if run==True:
55
+ # run image selection if keep style is false
56
+ if keep_style==False
57
+ path = 'stylesv2'
58
+ styles = os.listdir(path)
59
+ params.style_weight = style_weight
60
  st.session_state.submitted = True
61
  my_bar.progress(neural_style.transfer(params))
62
 
 
66
  result = Image.open('out.png')
67
  st.image(result, width=500)
68
  buf = BytesIO()
69
+ result.save(buf, format="png")
70
+ if len(os.listdir('generated_sampples') <= 10:
71
+ result.save(f"generated_sampples/{str(len(os.listdir('generated_sampples'))}.png")
72
  byte_im = buf.getvalue()
73
  run =st.download_button(label="Download Image", data=byte_im, file_name='afrodreams.jpg', mime="image/png")
74
+ #keeping the current style by update the weight
75
+ keep_style = st.sidebar.checkbox("Keep current style")
76
+
77
 
78
 
79