Spaces:
Sleeping
Sleeping
File size: 1,605 Bytes
5f36299 |
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 |
import streamlit as st
from utils import detect_license_plate, load_image_from_upload, load_image_from_url
import io
from PIL import Image
import numpy as np
def render_chat_ui(model):
st.markdown("Chat-style license plate detector. Upload an image or paste a URL.")
history = st.session_state.get("chat_history", [])
input_mode = st.radio("Choose Input Type", ["Upload Image", "Image URL"])
# Input
uploaded_file = None
image_url = None
if input_mode == "Upload Image":
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
else:
image_url = st.text_input("Paste image URL")
submit = st.button("Detect License Plate")
if submit:
if input_mode == "Upload Image" and uploaded_file is not None:
image = load_image_from_upload(uploaded_file)
label = "User uploaded an image."
elif input_mode == "Image URL" and image_url.strip():
image = load_image_from_url(image_url)
label = f"User sent image URL: {image_url}"
else:
st.warning("Please provide a valid image.")
return
st.session_state.chat_history = history + [(label, image)]
# Detect and display
with st.spinner("Detecting license plate..."):
result_img = detect_license_plate(model, image)
st.image(result_img, caption="Bounding box", use_column_width=True)
# Save result to history
st.session_state.chat_history.append(("Bounding box", result_img))
|