Spaces:
Configuration error
Configuration error
Danila-Pechenev
commited on
Commit
•
105b241
1
Parent(s):
018ea0f
Add download button
Browse files- app/app.py +8 -1
- app/model.py +4 -2
app/app.py
CHANGED
@@ -17,6 +17,11 @@ def describe_service():
|
|
17 |
st.subheader("Just upload your low-light image and get the processed one!")
|
18 |
|
19 |
|
|
|
|
|
|
|
|
|
|
|
20 |
def process_image():
|
21 |
uploaded_file: io.BytesIO = st.file_uploader(
|
22 |
label="Choose a file (you can upload new files without refreshing the page)",
|
@@ -25,9 +30,11 @@ def process_image():
|
|
25 |
if uploaded_file:
|
26 |
placeholder: st.delta_generator.DeltaGenerator = st.empty()
|
27 |
placeholder.info("The image is being processed. It may take some time. Wait, please...")
|
28 |
-
image: Image.Image =
|
29 |
placeholder.empty()
|
30 |
placeholder.image(image)
|
|
|
|
|
31 |
|
32 |
|
33 |
def main():
|
|
|
17 |
st.subheader("Just upload your low-light image and get the processed one!")
|
18 |
|
19 |
|
20 |
+
@st.experimental_memo
|
21 |
+
def call_model(uploaded_file):
|
22 |
+
return model.run_model(uploaded_file, st.session_state["model"])
|
23 |
+
|
24 |
+
|
25 |
def process_image():
|
26 |
uploaded_file: io.BytesIO = st.file_uploader(
|
27 |
label="Choose a file (you can upload new files without refreshing the page)",
|
|
|
30 |
if uploaded_file:
|
31 |
placeholder: st.delta_generator.DeltaGenerator = st.empty()
|
32 |
placeholder.info("The image is being processed. It may take some time. Wait, please...")
|
33 |
+
image: Image.Image = call_model(uploaded_file)
|
34 |
placeholder.empty()
|
35 |
placeholder.image(image)
|
36 |
+
with open("user_data/output.jpg", "rb") as file:
|
37 |
+
st.download_button(label="Download lightened image", data=file, file_name="lightened.jpg", mime="image/jpg")
|
38 |
|
39 |
|
40 |
def main():
|
app/model.py
CHANGED
@@ -3,6 +3,7 @@ from tensorflow import keras
|
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
5 |
import io
|
|
|
6 |
|
7 |
|
8 |
def create_model() -> keras.Model:
|
@@ -27,6 +28,7 @@ def run_model(image_bytes: io.BytesIO, model: keras.Model) -> Image.Image:
|
|
27 |
output_image_array5: np.ndarray = output_image_array3.astype(np.uint8)
|
28 |
output_image1: Image.Image = Image.fromarray(output_image_array5)
|
29 |
output_image2: Image.Image = output_image1.resize((width, height))
|
30 |
-
|
31 |
-
|
|
|
32 |
return output_image2
|
|
|
3 |
from PIL import Image
|
4 |
import numpy as np
|
5 |
import io
|
6 |
+
import os
|
7 |
|
8 |
|
9 |
def create_model() -> keras.Model:
|
|
|
28 |
output_image_array5: np.ndarray = output_image_array3.astype(np.uint8)
|
29 |
output_image1: Image.Image = Image.fromarray(output_image_array5)
|
30 |
output_image2: Image.Image = output_image1.resize((width, height))
|
31 |
+
if not os.path.exists("user_data"):
|
32 |
+
os.makedirs("user_data")
|
33 |
+
output_image2.save("user_data/output.jpg")
|
34 |
return output_image2
|