Spaces:
Runtime error
Runtime error
File size: 1,546 Bytes
a1008dc 3120f87 a1008dc 075c89b efcf544 03f785d 913f07a 03f785d |
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 |
import streamlit as st
from PIL import Image
import re
import requests
from io import BytesIO
import segmentation
def init():
st.set_page_config(page_title="Semantic image segmentation")
st.session_state["model"] = segmentation.create_model()
st.session_state["feature_extractor"] = segmentation.create_feature_extractor()
@st.experimental_memo(show_spinner=False)
def process_file(file):
return segmentation.segment(
Image.open(file),
st.session_state["model"],
st.session_state["feature_extractor"]
)
def download_button(file, name, format):
st.download_button(
label="Download processed image",
data=file,
file_name=name,
mime="image/" + format
)
def run():
st.title("Semantic image segmentation")
img_url = st.text_input('Image URL', 'https://images.unsplash.com/photo-1556911220-bff31c812dba?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2468&q=80')
st.caption('Downloading Image...')
file = requests.get(img_url).content
if not file:
return
placeholder = st.empty()
placeholder.info(
"Processing..."
)
#image = process_file(file)
image = file
placeholder.empty()
placeholder.image(image)
filename = file.name
format = re.findall("\..*$", filename)[0][1:]
image = Image.fromarray(image)
buf = BytesIO()
image.save(buf, format="JPEG")
byte_image = buf.getvalue()
download_button(byte_image, filename, format)
|