Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,33 +12,33 @@ def zoom_at(img, x, y, zoom):
|
|
12 |
x + w / zoom2, y + h / zoom2))
|
13 |
return img.resize((w, h), Image.LANCZOS)
|
14 |
|
15 |
-
st.title("
|
16 |
|
17 |
uploaded_files = st.file_uploader("Upload Images", accept_multiple_files=True, type="jpg")
|
18 |
|
19 |
if uploaded_files:
|
20 |
img_index = st.selectbox("Select Image", range(len(uploaded_files)))
|
|
|
|
|
21 |
x = st.slider("X Coordinate", 0, 500, 205)
|
22 |
y = st.slider("Y Coordinate", 0, 500, 250)
|
23 |
zoom = st.slider("Zoom", 1, 10, 5)
|
24 |
contrast = st.slider("Contrast", 0.0, 5.0, 1.0)
|
25 |
brightness = st.slider("Brightness", 0.0, 5.0, 1.0)
|
26 |
sharpness = st.slider("Sharpness", 0.0, 2.0, 1.0)
|
27 |
-
save_image = st.checkbox("Save Image")
|
28 |
|
29 |
-
img_data = uploaded_files[img_index].read()
|
30 |
-
img = Image.open(io.BytesIO(img_data)).resize((500, 500))
|
31 |
img_zoomed = zoom_at(img, x, y, zoom)
|
32 |
img_contrast = ImageEnhance.Contrast(img_zoomed).enhance(contrast)
|
33 |
img_bright = ImageEnhance.Brightness(img_contrast).enhance(brightness)
|
34 |
img_sharp = ImageEnhance.Sharpness(img_bright).enhance(sharpness)
|
35 |
|
|
|
|
|
|
|
36 |
if save_image:
|
37 |
img_sharp.save("image-processed.jpg")
|
38 |
st.success("Image saved as image-processed.jpg")
|
39 |
|
40 |
-
st.image(img_sharp, caption="Processed Image", use_column_width=True)
|
41 |
-
|
42 |
description = st.text_area("Describe the image", "")
|
43 |
if st.button("Save Description"):
|
44 |
with open("saved_image_description.txt", "w") as f:
|
@@ -63,4 +63,4 @@ if uploaded_files:
|
|
63 |
os.rename("image-processed.jpg", f"img_processed{file_ext}.jpg")
|
64 |
os.rename("saved_image_parameters.json", f"saved_image_parameters{file_ext}.json")
|
65 |
os.rename("saved_image_description.txt", f"saved_image_description{file_ext}.txt")
|
66 |
-
st.success("Files renamed successfully")
|
|
|
12 |
x + w / zoom2, y + h / zoom2))
|
13 |
return img.resize((w, h), Image.LANCZOS)
|
14 |
|
15 |
+
st.title("Cell Explorer")
|
16 |
|
17 |
uploaded_files = st.file_uploader("Upload Images", accept_multiple_files=True, type="jpg")
|
18 |
|
19 |
if uploaded_files:
|
20 |
img_index = st.selectbox("Select Image", range(len(uploaded_files)))
|
21 |
+
img_data = uploaded_files[img_index].read()
|
22 |
+
img = Image.open(io.BytesIO(img_data)).resize((500, 500))
|
23 |
x = st.slider("X Coordinate", 0, 500, 205)
|
24 |
y = st.slider("Y Coordinate", 0, 500, 250)
|
25 |
zoom = st.slider("Zoom", 1, 10, 5)
|
26 |
contrast = st.slider("Contrast", 0.0, 5.0, 1.0)
|
27 |
brightness = st.slider("Brightness", 0.0, 5.0, 1.0)
|
28 |
sharpness = st.slider("Sharpness", 0.0, 2.0, 1.0)
|
|
|
29 |
|
|
|
|
|
30 |
img_zoomed = zoom_at(img, x, y, zoom)
|
31 |
img_contrast = ImageEnhance.Contrast(img_zoomed).enhance(contrast)
|
32 |
img_bright = ImageEnhance.Brightness(img_contrast).enhance(brightness)
|
33 |
img_sharp = ImageEnhance.Sharpness(img_bright).enhance(sharpness)
|
34 |
|
35 |
+
st.image(img_sharp, caption="Processed Image", use_column_width=True)
|
36 |
+
|
37 |
+
save_image = st.checkbox("Save Image")
|
38 |
if save_image:
|
39 |
img_sharp.save("image-processed.jpg")
|
40 |
st.success("Image saved as image-processed.jpg")
|
41 |
|
|
|
|
|
42 |
description = st.text_area("Describe the image", "")
|
43 |
if st.button("Save Description"):
|
44 |
with open("saved_image_description.txt", "w") as f:
|
|
|
63 |
os.rename("image-processed.jpg", f"img_processed{file_ext}.jpg")
|
64 |
os.rename("saved_image_parameters.json", f"saved_image_parameters{file_ext}.json")
|
65 |
os.rename("saved_image_description.txt", f"saved_image_description{file_ext}.txt")
|
66 |
+
st.success("Files renamed successfully")
|