Spaces:
Runtime error
Runtime error
File size: 2,090 Bytes
732b57d 75ed2e1 732b57d 75ed2e1 732b57d 75ed2e1 732b57d 75ed2e1 732b57d 75ed2e1 732b57d 75ed2e1 732b57d 75ed2e1 732b57d 75ed2e1 732b57d |
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 63 64 65 66 67 68 69 70 |
import os
import streamlit as st
import tensorflow as tf
from ..image_utils import load_img, imshow, transform_img
def upload_image_url(ImageSelectionPrompt, ImageType, image_upload_method):
st.write(f"{ImageSelectionPrompt}: {image_upload_method}")
url = st.text_input(f"{ImageType} Image URL")
try:
image_path = tf.keras.utils.get_file(
os.path.join(os.getcwd(), f"{ImageType.lower()}.jpg"), url
)
except:
pass
try:
return load_img(image_path)
except:
pass
def upload_image_file(ImageSelectionPrompt, ImageType, image_upload_method):
st.write(f"{ImageSelectionPrompt}: {image_upload_method}")
image_file = st.file_uploader(
f"Upload {ImageType} Image File (png or jpg)", type=("png", "jpg")
)
try:
image_file = image_file.read()
return transform_img(image_file)
except:
pass
def upload_image_capture(ImageSelectionPrompt, ImageType, image_upload_method):
st.write(f"{ImageSelectionPrompt}: {image_upload_method}")
image_file = st.camera_input(f"Capture {ImageType} Image")
try:
image_file = image_file.read()
return transform_img(image_file)
except:
pass
def upload_image(ColumnTitle, ImageSelectionPrompt, ImageType, KeyString):
st.write(ColumnTitle)
image_upload_method = st.radio(
label="", options=["π URL", "π File Upload", "πΈ Capture"], key=KeyString
)
if image_upload_method == "π URL":
image_file = upload_image_url(
ImageSelectionPrompt, ImageType, image_upload_method
)
if image_upload_method == "π File Upload":
image_file = upload_image_file(
ImageSelectionPrompt, ImageType, image_upload_method
)
if image_upload_method == "πΈ Capture":
image_file = upload_image_capture(
ImageSelectionPrompt, ImageType, image_upload_method
)
try:
st.write(f"{ImageType} Image")
st.image(imshow(image_file))
return image_file
except:
pass
|