Spaces:
Runtime error
Runtime error
File size: 2,237 Bytes
fe8fd9f 8aaffa8 fe8fd9f 5cc0cd0 fe8fd9f 2aa07dc fe8fd9f 8aaffa8 fe8fd9f 81ec8c5 8aaffa8 81ec8c5 eb51f8c 81ec8c5 7766cc1 81ec8c5 3713c83 8aaffa8 fe8fd9f 32cd696 2aa07dc 4758b18 2aa07dc fe8fd9f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import neural_style
import streamlit as st
import os
import random
import numpy as np
#import cv2
from PIL import Image, ImageEnhance
from io import BytesIO
st.set_page_config(layout="wide")
#Create two columns with different width
col1, col2 = st.columns( [0.8, 0.2])
with col1: # To display the header text using css style
st.markdown(""" <style> .font {
font-size:35px ; font-family: 'Cooper Black'; color: #FF9633;}
</style> """, unsafe_allow_html=True)
st.markdown('<p class="font">Upload your photo here...</p>', unsafe_allow_html=True)
#Add a header and expander in side bar
st.sidebar.markdown('<p class="font">Afrodreams.AI</p>', unsafe_allow_html=True)
with st.sidebar.expander("About the App"):
st.write("""
This app takes in your image and styles it with a unique african art.""")
#Add file uploader to allow users to upload photos
uploaded_file = st.file_uploader("", type=['jpg','png','jpeg'])
#Add 'before' and 'after' columns
if uploaded_file is not None:
image = Image.open(uploaded_file)
col1, col2 = st.columns( [0.5, 0.5])
with col1:
st.markdown('<p style="text-align: center;">Before</p>',unsafe_allow_html=True)
st.image(image,width=300)
with col2:
st.markdown('<p style="text-align: center;">After</p>',unsafe_allow_html=True)
# add a button
run = st.button('Generate Art')
if run==True:
with st.spinner('Wait for it...'):
params = neural_style.TransferParams()
params.gpu = "c"
params.backend = "mkl"
params.image_size = 300
params.content_image = uploaded_file
path = 'stylesv2'
styles = os.listdir(path)
params.style_image = path + '/' + random.choice(styles)
neural_style.transfer(params)
#display image when done.
with col2:
result = Image.open('out.png')
st.image(result, width=500)
buf = BytesIO()
result.save(buf, format="JPEG")
byte_im = buf.getvalue()
run =st.download_button(label="Download Image", data=byte_im, file_name='afrodreams.jpg', mime="image/png")
|