Spaces:
Sleeping
Sleeping
sravanneeli
commited on
Commit
·
f6be055
1
Parent(s):
2b742c3
base version
Browse files- __init__.py +0 -0
- main.py +43 -0
- requirements.txt +7 -0
- vision_models.py +60 -0
__init__.py
ADDED
File without changes
|
main.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
os.environ["KERAS_BACKEND"] = "jax"
|
4 |
+
|
5 |
+
import streamlit as st
|
6 |
+
from vision_models import vision_page
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
def main():
|
11 |
+
# Set up the main layout and title
|
12 |
+
st.set_page_config(page_title="ModelLens", layout="centered")
|
13 |
+
st.title("ModelLens")
|
14 |
+
|
15 |
+
# Sidebar for navigation
|
16 |
+
st.sidebar.title("Navigation")
|
17 |
+
options = ["Vision", "NLP", "About"]
|
18 |
+
choice = st.sidebar.radio("Go to", options)
|
19 |
+
|
20 |
+
# Route to the selected page
|
21 |
+
if choice == "Vision":
|
22 |
+
vision_page()
|
23 |
+
elif choice == "NLP":
|
24 |
+
nlp_page()
|
25 |
+
elif choice == "About":
|
26 |
+
about_page()
|
27 |
+
|
28 |
+
|
29 |
+
def nlp_page():
|
30 |
+
st.header("Natural Language Processing")
|
31 |
+
st.write("This section is for exploring NLP models.")
|
32 |
+
# Add your NLP model visualization or interaction code here
|
33 |
+
|
34 |
+
|
35 |
+
def about_page():
|
36 |
+
st.header("About Page")
|
37 |
+
st.write(
|
38 |
+
"This app was created to demonstrate a basic Streamlit application layout."
|
39 |
+
)
|
40 |
+
|
41 |
+
|
42 |
+
if __name__ == "__main__":
|
43 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
keras-hub==0.18.1
|
2 |
+
streamlit==1.41.1
|
3 |
+
keras==3.8.0
|
4 |
+
ruff==0.9.3
|
5 |
+
jax==0.5.0
|
6 |
+
tensorflow==2.18.0
|
7 |
+
tensorflow_text==2.18.1
|
vision_models.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import keras_hub
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
classification_models = {
|
7 |
+
"ResNet18": "resnet_18_imagenet",
|
8 |
+
"ResNet50": "resnet_50_imagenet"
|
9 |
+
}
|
10 |
+
|
11 |
+
|
12 |
+
def load_preprocessor(model_name):
|
13 |
+
return keras_hub.models.ImageClassifierPreprocessor.from_preset(model_name)
|
14 |
+
|
15 |
+
def load_model(model_name):
|
16 |
+
"""Load a pre-trained model from KerasHub."""
|
17 |
+
return keras_hub.models.ImageClassifier.from_preset(model_name)
|
18 |
+
|
19 |
+
def upload_image():
|
20 |
+
"""Common function for uploading an image."""
|
21 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
22 |
+
if uploaded_file:
|
23 |
+
image = Image.open(uploaded_file)
|
24 |
+
return np.expand_dims(np.array(image).astype("float32"), axis=0)
|
25 |
+
return None
|
26 |
+
|
27 |
+
def vision_page():
|
28 |
+
st.header("Vision Models")
|
29 |
+
st.write("Explore Vision Models including Image Classification, Object Detection, and Segmentation.")
|
30 |
+
|
31 |
+
# Tabs for different vision tasks
|
32 |
+
tab1, tab2, tab3 = st.tabs(["Image Classification", "Object Detection", "Segmentation"])
|
33 |
+
|
34 |
+
with tab1:
|
35 |
+
st.subheader("Image Classification")
|
36 |
+
model_name = st.selectbox("Choose a pre-trained model:", list(classification_models.keys()))
|
37 |
+
preprocessor = load_preprocessor(classification_models[model_name])
|
38 |
+
model = load_model(classification_models[model_name])
|
39 |
+
|
40 |
+
image = upload_image()
|
41 |
+
if image is not None:
|
42 |
+
preprocessed_image = preprocessor(image)
|
43 |
+
raw_predictions = model(preprocessed_image)
|
44 |
+
predictions = keras_hub.utils.decode_imagenet_predictions(raw_predictions)
|
45 |
+
|
46 |
+
col1, col2 = st.columns([1, 1])
|
47 |
+
with col1:
|
48 |
+
st.image(image[0].astype("uint8"), caption="Uploaded Image", use_container_width=True)
|
49 |
+
with col2:
|
50 |
+
st.write("##### Top Predictions:")
|
51 |
+
for idx, (class_name, score) in enumerate(predictions[0]):
|
52 |
+
st.write(f"{idx + 1}: {class_name}")
|
53 |
+
|
54 |
+
with tab2:
|
55 |
+
st.subheader("Object Detection")
|
56 |
+
st.write("Object Detection functionality is under development.")
|
57 |
+
|
58 |
+
with tab3:
|
59 |
+
st.subheader("Segmentation")
|
60 |
+
st.write("Segmentation functionality is under development.")
|