Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import streamlit as st
|
|
| 2 |
from PIL import Image, ImageFilter
|
| 3 |
import numpy as np
|
| 4 |
import pandas as pd
|
|
|
|
| 5 |
|
| 6 |
# Simple app: convert user input into ASCII codes and binary labels
|
| 7 |
|
|
@@ -14,9 +15,6 @@ def string_to_binary_labels(s: str) -> list[int]:
|
|
| 14 |
return bits
|
| 15 |
|
| 16 |
def clean_image(img: Image.Image, min_size: int = 256) -> Image.Image:
|
| 17 |
-
"""
|
| 18 |
-
Preprocess image to reduce noise: resize if needed and apply light blur.
|
| 19 |
-
"""
|
| 20 |
img = img.convert("RGB")
|
| 21 |
if img.width < min_size or img.height < min_size:
|
| 22 |
img = img.resize((min_size, min_size))
|
|
@@ -121,9 +119,14 @@ with tab2:
|
|
| 121 |
img = Image.open(uploaded_file)
|
| 122 |
st.image(img, caption="Uploaded Image", use_column_width=True)
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
max_pixels = st.slider("Max number of pixels to encode", min_value=32, max_value=1024, value=256, step=32)
|
| 125 |
|
| 126 |
-
binary_labels = image_to_binary_labels_rgb(
|
| 127 |
|
| 128 |
st.subheader("Binary Labels from Image")
|
| 129 |
num_groups = (len(binary_labels) + 31) // 32
|
|
|
|
| 2 |
from PIL import Image, ImageFilter
|
| 3 |
import numpy as np
|
| 4 |
import pandas as pd
|
| 5 |
+
from streamlit_cropper import st_cropper
|
| 6 |
|
| 7 |
# Simple app: convert user input into ASCII codes and binary labels
|
| 8 |
|
|
|
|
| 15 |
return bits
|
| 16 |
|
| 17 |
def clean_image(img: Image.Image, min_size: int = 256) -> Image.Image:
|
|
|
|
|
|
|
|
|
|
| 18 |
img = img.convert("RGB")
|
| 19 |
if img.width < min_size or img.height < min_size:
|
| 20 |
img = img.resize((min_size, min_size))
|
|
|
|
| 119 |
img = Image.open(uploaded_file)
|
| 120 |
st.image(img, caption="Uploaded Image", use_column_width=True)
|
| 121 |
|
| 122 |
+
st.subheader("Crop the image with drag and select")
|
| 123 |
+
cropped_img = st_cropper(img, realtime_update=True, box_color='blue', aspect_ratio=None)
|
| 124 |
+
|
| 125 |
+
st.image(cropped_img, caption="Cropped Image", use_column_width=True)
|
| 126 |
+
|
| 127 |
max_pixels = st.slider("Max number of pixels to encode", min_value=32, max_value=1024, value=256, step=32)
|
| 128 |
|
| 129 |
+
binary_labels = image_to_binary_labels_rgb(cropped_img, max_pixels=max_pixels)
|
| 130 |
|
| 131 |
st.subheader("Binary Labels from Image")
|
| 132 |
num_groups = (len(binary_labels) + 31) // 32
|