-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
60 lines (45 loc) Β· 1.56 KB
/
app.py
File metadata and controls
60 lines (45 loc) Β· 1.56 KB
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
import sys
from pathlib import Path
import streamlit as st
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import os
ROOT_DIR = Path(__file__).resolve().parents[1]
if str(ROOT_DIR) not in sys.path:
sys.path.append(str(ROOT_DIR))
from model_loader import load_model, predict
st.set_page_config(page_title="Xplendia Off-Road AI", layout="wide")
st.title("π Xplendia Off-Road Autonomy Vision")
st.write("Upload an off-road image and view AI terrain segmentation output.")
@st.cache_resource
def get_model():
return load_model()
uploaded = st.file_uploader("Upload vehicle camera image", type=["png", "jpg", "jpeg"])
st.sidebar.header("Color Legend")
st.sidebar.write("""
Cyan / Blue β Sky
Orange β Soil / terrain
Green β Vegetation / grass
Olive β Bushes / dry grass
Purple β Ground clutter
Gray / Brown β Rocks / rough terrain
""")
if uploaded:
image = Image.open(uploaded)
st.subheader("Vehicle Camera Input")
st.image(image, use_container_width=True)
st.subheader("AI Segmentation Output")
try:
model = get_model()
prediction = predict(model, image)
fig, ax = plt.subplots()
ax.imshow(np.array(prediction))
ax.axis("off")
st.pyplot(fig)
st.success("Terrain map generated successfully.")
st.info("Driving Decision: Proceed carefully. Avoid dense rocks / vegetation-heavy regions.")
except FileNotFoundError as exc:
st.error(f"Model file not found: {exc}")
except Exception as exc:
st.error(f"Prediction failed: {exc}")