harshinde commited on
Commit
8fded10
·
verified ·
1 Parent(s): 22c4819

Upload src/streamlit_app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +100 -0
src/streamlit_app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import torch
3
+ import numpy as np
4
+ import matplotlib.pyplot as plt
5
+ import yaml
6
+ import os
7
+ from pathlib import Path
8
+ from model_downloader import ModelDownloader
9
+
10
+ # Import models
11
+ from .deeplabv3plus_model import LandslideModel as DeepLabV3PlusModel
12
+ from .vgg16_model import LandslideModel as VGG16Model
13
+ from .resnet34_model import LandslideModel as ResNet34Model
14
+ from .efficientnetb0_model import LandslideModel as EfficientNetB0Model
15
+ from .mitb1_model import LandslideModel as MiTB1Model
16
+ from .inceptionv4_model import LandslideModel as InceptionV4Model
17
+ from .densenet121_model import LandslideModel as DenseNet121Model
18
+ from .resnext50_32x4d_model import LandslideModel as ResNeXt50_32X4DModel
19
+ from .se_resnet50_model import LandslideModel as SEResNet50Model
20
+ from .se_resnext50_32x4d_model import LandslideModel as SEResNeXt50_32X4DModel
21
+ from .segformer_model import LandslideModel as SegFormerB2Model
22
+ from .inceptionresnetv2_model import LandslideModel as InceptionResNetV2Model
23
+
24
+ # Initialize model downloader
25
+ model_downloader = ModelDownloader()
26
+
27
+ # Model descriptions
28
+ model_descriptions = {
29
+ "MobileNetV2": {"type": "mobilenet_v2", "description": "MobileNetV2 is a lightweight deep learning model for image classification and segmentation."},
30
+ "VGG16": {"type": "vgg16", "description": "VGG16 is a popular deep learning model known for its simplicity and depth."},
31
+ "ResNet34": {"type": "resnet34", "description": "ResNet34 is a deep residual network that helps in training very deep networks."},
32
+ "EfficientNetB0": {"type": "efficientnet_b0", "description": "EfficientNetB0 is part of the EfficientNet family, known for its efficiency and performance."},
33
+ "MiT-B1": {"type": "mit_b1", "description": "MiT-B1 is a transformer-based model designed for segmentation tasks."},
34
+ "InceptionV4": {"type": "inceptionv4", "description": "InceptionV4 is a convolutional neural network known for its inception modules."},
35
+ "DeepLabV3+": {"type": "deeplabv3plus", "description": "DeepLabV3+ is an advanced model for semantic image segmentation."},
36
+ "DenseNet121": {"type": "densenet121", "description": "DenseNet121 is a densely connected convolutional network for image classification and segmentation."},
37
+ "ResNeXt50_32X4D": {"type": "resnext50_32x4d", "description": "ResNeXt50_32X4D is a highly modularized network aimed at improving accuracy."},
38
+ "SEResNet50": {"type": "se_resnet50", "description": "SEResNet50 is a ResNet model with squeeze-and-excitation blocks for better feature recalibration."},
39
+ "SEResNeXt50_32X4D": {"type": "se_resnext50_32x4d", "description": "SEResNeXt50_32X4D combines ResNeXt and SE blocks for improved performance."},
40
+ "SegFormerB2": {"type": "segformer", "description": "SegFormerB2 is a transformer-based model for semantic segmentation."},
41
+ "InceptionResNetV2": {"type": "inceptionresnetv2", "description": "InceptionResNetV2 is a hybrid model combining Inception and ResNet architectures."},
42
+ }
43
+
44
+ # Streamlit app
45
+ st.set_page_config(page_title="Landslide Detection", layout="wide")
46
+
47
+ st.title("Landslide Detection")
48
+ st.markdown("""
49
+ ## Instructions
50
+ 1. Select a model from the sidebar.
51
+ 2. Upload one or more `.h5` files.
52
+ 3. The app will process the files and display the input image, prediction, and overlay.
53
+ 4. You can download the prediction results.
54
+ """)
55
+
56
+ # Sidebar for model selection
57
+ st.sidebar.title("Model Selection")
58
+ model_type = st.sidebar.selectbox("Select Model", list(model_descriptions.keys()))
59
+
60
+ # Get model details
61
+ config = {
62
+ 'model_config': {
63
+ 'model_type': model_descriptions[model_type]['type'],
64
+ 'in_channels': 14,
65
+ 'num_classes': 1
66
+ }
67
+ }
68
+
69
+ # Show model description
70
+ st.sidebar.markdown(f"**Model Type:** {model_descriptions[model_type]['type']}")
71
+ st.sidebar.markdown(f"**Description:** {model_descriptions[model_type]['description']}")
72
+
73
+ try:
74
+ # Get the appropriate model class
75
+ if model_type == "DeepLabV3+":
76
+ model_class = DeepLabV3PlusModel
77
+ else:
78
+ model_class = locals()[model_type.replace("-", "") + "Model"]
79
+
80
+ # Get model path from downloader
81
+ model_name = model_descriptions[model_type]['type'].replace("+", "plus").lower()
82
+ model_path = model_downloader.get_model_path(model_name)
83
+ st.success(f"Model {model_type} loaded successfully!")
84
+
85
+ # File uploader
86
+ uploaded_files = st.file_uploader("Upload H5 files", type=['h5'], accept_multiple_files=True)
87
+
88
+ if uploaded_files:
89
+ # Process each uploaded file
90
+ for uploaded_file in uploaded_files:
91
+ st.write(f"Processing {uploaded_file.name}...")
92
+ # Add your file processing logic here
93
+
94
+ except FileNotFoundError as e:
95
+ st.error(f"Model file not found: {str(e)}")
96
+ st.error("Please ensure all model files are present in the models directory")
97
+ st.stop()
98
+ except Exception as e:
99
+ st.error(f"Error: {str(e)}")
100
+ st.stop()