Spaces:
No application file
No application file
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +7 -16
src/streamlit_app.py
CHANGED
|
@@ -8,21 +8,12 @@ from PIL import Image
|
|
| 8 |
import torch
|
| 9 |
from transformers import DetrImageProcessor, DetrForObjectDetection
|
| 10 |
|
| 11 |
-
# ===
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
# === Load Hugging Face Model ===
|
| 15 |
-
processor = DetrImageProcessor.from_pretrained(
|
| 16 |
-
"NaveenKumar5/Solar_panel_fault_detection",
|
| 17 |
-
cache_dir="./model_cache"
|
| 18 |
-
)
|
| 19 |
-
model = DetrForObjectDetection.from_pretrained(
|
| 20 |
-
"NaveenKumar5/Solar_panel_fault_detection",
|
| 21 |
-
cache_dir="./model_cache"
|
| 22 |
-
)
|
| 23 |
model.eval()
|
| 24 |
|
| 25 |
-
# === Streamlit App ===
|
| 26 |
st.set_page_config(page_title="Solar Panel Fault Detection", layout="wide")
|
| 27 |
st.title("🔍 Solar Panel Fault Detection (DETR - Hugging Face)")
|
| 28 |
st.write("Upload a thermal video (MP4). Faults will be detected using a DETR model from Hugging Face.")
|
|
@@ -60,7 +51,7 @@ def detect_faults(frame, frame_idx, fps):
|
|
| 60 |
})
|
| 61 |
return frame, faults
|
| 62 |
|
| 63 |
-
# === Video Processing ===
|
| 64 |
def process_video(video_path):
|
| 65 |
cap = cv2.VideoCapture(video_path)
|
| 66 |
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
|
@@ -90,7 +81,7 @@ def process_video(video_path):
|
|
| 90 |
writer.release()
|
| 91 |
return output_path, fault_log
|
| 92 |
|
| 93 |
-
# === CSV
|
| 94 |
def convert_df(df):
|
| 95 |
return df.to_csv(index=False).encode('utf-8')
|
| 96 |
|
|
@@ -120,4 +111,4 @@ if uploaded_file:
|
|
| 120 |
os.unlink(output_path)
|
| 121 |
|
| 122 |
st.markdown("---")
|
| 123 |
-
st.caption("Built with Streamlit + Hugging Face DETR + OpenCV")
|
|
|
|
| 8 |
import torch
|
| 9 |
from transformers import DetrImageProcessor, DetrForObjectDetection
|
| 10 |
|
| 11 |
+
# === Load Hugging Face Model using default cache (handles permissions safely) ===
|
| 12 |
+
processor = DetrImageProcessor.from_pretrained("NaveenKumar5/Solar_panel_fault_detection")
|
| 13 |
+
model = DetrForObjectDetection.from_pretrained("NaveenKumar5/Solar_panel_fault_detection")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
model.eval()
|
| 15 |
|
| 16 |
+
# === Streamlit App Setup ===
|
| 17 |
st.set_page_config(page_title="Solar Panel Fault Detection", layout="wide")
|
| 18 |
st.title("🔍 Solar Panel Fault Detection (DETR - Hugging Face)")
|
| 19 |
st.write("Upload a thermal video (MP4). Faults will be detected using a DETR model from Hugging Face.")
|
|
|
|
| 51 |
})
|
| 52 |
return frame, faults
|
| 53 |
|
| 54 |
+
# === Video Processing Function ===
|
| 55 |
def process_video(video_path):
|
| 56 |
cap = cv2.VideoCapture(video_path)
|
| 57 |
fps = int(cap.get(cv2.CAP_PROP_FPS))
|
|
|
|
| 81 |
writer.release()
|
| 82 |
return output_path, fault_log
|
| 83 |
|
| 84 |
+
# === CSV Helper ===
|
| 85 |
def convert_df(df):
|
| 86 |
return df.to_csv(index=False).encode('utf-8')
|
| 87 |
|
|
|
|
| 111 |
os.unlink(output_path)
|
| 112 |
|
| 113 |
st.markdown("---")
|
| 114 |
+
st.caption("Built with Streamlit + Hugging Face DETR + OpenCV")
|