nazlicanto commited on
Commit
cfd86c0
1 Parent(s): e6b5986

error handling V2

Browse files
Files changed (1) hide show
  1. app06.py +14 -5
app06.py CHANGED
@@ -1,17 +1,26 @@
1
- %%writefile app06_.py
2
-
3
  import streamlit as st
4
  from transformers import SegformerForSemanticSegmentation, SegformerImageProcessor
5
  from PIL import Image
6
  import numpy as np
7
  import torch
 
8
 
9
  # Load the model and processor
10
- model_path = "/home/user/app/defectdetection/model"
11
- model = SegformerForSemanticSegmentation.from_pretrained(model_path, local_files_only=True)
12
- preprocessor = SegformerImageProcessor.from_pretrained(model_path, local_files_only=True)
13
  model.eval()
14
 
 
 
 
 
 
 
 
 
 
 
15
  st.title("PCB Defect Detection")
16
 
17
  # Upload image in Streamlit
 
 
 
1
  import streamlit as st
2
  from transformers import SegformerForSemanticSegmentation, SegformerImageProcessor
3
  from PIL import Image
4
  import numpy as np
5
  import torch
6
+ import os
7
 
8
  # Load the model and processor
9
+ model_dir = "C://Users//nazli//OneDrive//Desktop//PCB-Defect-Detection-Segmentation//model11//model//"
10
+ model = SegformerForSemanticSegmentation.from_pretrained(model_dir)
11
+ processor = SegformerImageProcessor.from_pretrained(model_dir)
12
  model.eval()
13
 
14
+
15
+ try:
16
+ model = SegformerForSemanticSegmentation.from_pretrained(model_dir, local_files_only=True)
17
+ preprocessor = SegformerImageProcessor.from_pretrained(model_dir, local_files_only=True)
18
+ except Exception as e:
19
+ existing_files = os.listdir(model_dir)
20
+ error_msg = f"Error: {e}\nFiles in directory: {existing_files}"
21
+ st.write(error_msg)
22
+
23
+
24
  st.title("PCB Defect Detection")
25
 
26
  # Upload image in Streamlit