Spaces:
Runtime error
Runtime error
Upload initial files
Browse files- app.py +30 -0
- neural_style_transfer/__init__.py +21 -0
- neural_style_transfer/__pycache__/__init__.cpython-311.pyc +0 -0
- requirements.txt +5 -0
- sample/femme_nue_assise.jpg +0 -0
- sample/konark.jpg +0 -0
- sample/result.jpg +0 -0
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from neural_style_transfer import generate_img
|
3 |
+
|
4 |
+
def display_img(org_img, style_img):
|
5 |
+
img = generate_img(org_img, style_img)
|
6 |
+
st.image(img, caption='Result after Neural Style Transfer', use_column_width=True)
|
7 |
+
|
8 |
+
def main():
|
9 |
+
markdown = ""
|
10 |
+
with open('README.md', 'r') as f:
|
11 |
+
markdown = f.read()
|
12 |
+
st.markdown(markdown, unsafe_allow_html=True)
|
13 |
+
with st.container(border=True):
|
14 |
+
col1, col2 = st.columns(2)
|
15 |
+
with col1:
|
16 |
+
st.header('Original Image')
|
17 |
+
org_img = st.file_uploader(label='Upload original image', type=['png', 'jpg', 'jpeg'])
|
18 |
+
with col2:
|
19 |
+
st.header('Style Image')
|
20 |
+
style_img = st.file_uploader(label='Upload style image', type=['png', 'jpg', 'jpeg'])
|
21 |
+
|
22 |
+
if org_img is not None and style_img is not None:
|
23 |
+
if st.button("Submit"):
|
24 |
+
col1, col2, col3 = st.columns([1,2.5,1])
|
25 |
+
with col2:
|
26 |
+
display_img(org_img.read(), style_img.read())
|
27 |
+
|
28 |
+
|
29 |
+
if __name__ == '__main__':
|
30 |
+
main()
|
neural_style_transfer/__init__.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import matplotlib.pyplot as plt
|
3 |
+
import cv2 as cv
|
4 |
+
import tensorflow as tf
|
5 |
+
import tensorflow_hub as hub
|
6 |
+
|
7 |
+
model = hub.load('https://www.kaggle.com/models/google/arbitrary-image-stylization-v1/tensorFlow1/256/2')
|
8 |
+
|
9 |
+
def load_image(img_bytes):
|
10 |
+
img = tf.image.decode_image(img_bytes, channels=3)
|
11 |
+
img = tf.image.resize(img, [256, 256])
|
12 |
+
img = tf.image.convert_image_dtype(img, tf.float32)
|
13 |
+
img = tf.expand_dims(img/255.0, axis=0)
|
14 |
+
return img
|
15 |
+
|
16 |
+
def generate_img(org_img, style_img):
|
17 |
+
org_img = load_image(org_img)
|
18 |
+
style_img = load_image(style_img)
|
19 |
+
gen_img = model(tf.constant(org_img), tf.constant(style_img))[0]
|
20 |
+
img_arr = (np.array(gen_img)*255).astype(np.uint8)[0]
|
21 |
+
return img_arr
|
neural_style_transfer/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (1.79 kB). View file
|
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
matplotlib
|
3 |
+
opencv-python
|
4 |
+
tensorflow
|
5 |
+
tensorflow_hub
|
sample/femme_nue_assise.jpg
ADDED
![]() |
sample/konark.jpg
ADDED
![]() |
sample/result.jpg
ADDED
![]() |