Spaces:
Sleeping
Sleeping
import streamlit as st | |
from PIL import Image | |
from modInference import main | |
import numpy as np | |
import math | |
st.set_page_config(layout="wide") | |
st.markdown("") | |
showImg = Image.open('3dots.jpg') | |
ogInp = Image.open('3dots.jpg') | |
showImg = showImg.resize((200, 200)) | |
ogInp = ogInp.resize((200, 200)) | |
cellImgs = [] | |
st.title('MicroScan In Action!') | |
st.subheader("Enter an image of a thin blood smear. Preview the image and run the application. This program was developed by Anish Pallod =)") | |
input, outputIm = st.columns(2) | |
with input: | |
st.header("Input") | |
imageInput = st.file_uploader("Enter an image of a thin blood smear.") | |
if st.button("Run"): | |
if imageInput is not None: | |
image = Image.open(imageInput) | |
ogInp = image | |
img_array = np.array(image) | |
output, cellImgs = main("/home/anishpallod/Downloads/dependencies/best_model.pth", img_array) | |
showImg = Image.fromarray(output) | |
if st.button("Preview"): | |
if imageInput is not None: | |
image = Image.open(imageInput) | |
ogInp = image | |
st.write("-" * 34) | |
st.header("How it looks:") | |
st.image(ogInp) | |
else: | |
st.write("-" * 34) | |
st.header("How it looks:") | |
st.image(ogInp) | |
with outputIm: | |
st.header("General Output") | |
st.image(showImg) | |
st.write("-" * 34) | |
st.header("Segmented Cell Output") | |
st.markdown(""" | |
<style> | |
[data-testid=column] [data-testid=stVerticalBlock]{ | |
gap: 0.3rem; | |
} | |
</style> | |
""",unsafe_allow_html=True) | |
col1,col2,col3,col4,col5,col6,col7 = st.columns(7) | |
total = len(cellImgs) | |
print(cellImgs) | |
barrier = [] | |
for k in range(1, 8): | |
barrier.append(math.floor(total/7) * k) | |
leftOver = total % 7 | |
for k in range(leftOver): | |
barrier[k] += 1 | |
print(barrier) | |
with col1: | |
for x in cellImgs[0:barrier[0]]: | |
st.write(x[1]) | |
st.image(x[0]) | |
with col2: | |
for x in cellImgs[barrier[0]: barrier[1]]: | |
st.write(x[1]) | |
st.image(x[0]) | |
with col3: | |
for x in cellImgs[barrier[1]: barrier[2]]: | |
st.write(x[1]) | |
st.image(x[0]) | |
with col4: | |
for x in cellImgs[barrier [2]: barrier[3]]: | |
st.write(x[1]) | |
st.image(x[0]) | |
with col5: | |
for x in cellImgs[barrier[3]: barrier[4]]: | |
st.write(x[1]) | |
st.image(x[0]) | |
with col6: | |
for x in cellImgs[barrier[4]: barrier[5]]: | |
st.write(x[1]) | |
st.image(x[0]) | |
with col7: | |
for x in cellImgs[barrier[5]: barrier[6]]: | |
st.write(x[1]) | |
st.image(x[0]) | |
# with parameters: | |
# st.header("Parameters") | |