Daebin commited on
Commit
21ef916
ยท
verified ยท
1 Parent(s): e4760bd

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +42 -44
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,44 +1,42 @@
1
- import streamlit as st
2
- import torch
3
- import cv2
4
- import tempfile
5
- import os
6
- import numpy as np
7
- from PIL import Image
8
- from pathlib import Path
9
-
10
- @st.cache_resource
11
- def load_model(model_path):
12
- return torch.hub.load('ultralytics/yolov5', 'custom', path=model_path, force_reload=False)
13
-
14
- def detect_image(img, model):
15
- img_array = np.array(img.convert('RGB'))
16
- img_bgr = cv2.cvtColor(img_array, cv2.COLOR_RGB2BGR)
17
- result = model(img_bgr)
18
- result.render()
19
- for img in result.ims:
20
- yield Image.fromarray(img)
21
-
22
- def main():
23
- st.title("๐Ÿ”ฅ Ignition Point Detector")
24
- st.write("AI ๊ธฐ๋ฐ˜ ํ™”์žฌ ๋ฐœํ™”์ง€์  ํƒ์ง€ ์›น์•ฑ์ž…๋‹ˆ๋‹ค.")
25
- uploaded_model = st.file_uploader("๐Ÿ“ฆ YOLOv5 ๋ชจ๋ธ ํŒŒ์ผ (.pt)", type=['pt'])
26
- uploaded_images = st.file_uploader("๐Ÿ“ท ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ (์—ฌ๋Ÿฌ ์žฅ ๊ฐ€๋Šฅ)", type=['jpg', 'jpeg', 'png'], accept_multiple_files=True)
27
-
28
- if uploaded_model and uploaded_images:
29
- with tempfile.NamedTemporaryFile(delete=False, suffix=".pt") as tmp_model:
30
- tmp_model.write(uploaded_model.read())
31
- tmp_model_path = tmp_model.name
32
-
33
- model = load_model(tmp_model_path)
34
-
35
- for uploaded_image in uploaded_images:
36
- image = Image.open(uploaded_image)
37
- st.image(image, caption="๐Ÿ–ผ๏ธ ์›๋ณธ ์ด๋ฏธ์ง€", use_container_width=True)
38
-
39
- st.markdown("๐Ÿ” ๋ถ„์„ ๊ฒฐ๊ณผ:")
40
- for result_img in detect_image(image, model):
41
- st.image(result_img, caption="๐Ÿ”ฅ ํƒ์ง€๋œ ์ด๋ฏธ์ง€", use_container_width=True)
42
-
43
- if __name__ == "__main__":
44
- main()
 
1
+ import streamlit as st
2
+ import torch
3
+ import tempfile
4
+ import os
5
+ import cv2
6
+ from PIL import Image
7
+ import numpy as np
8
+
9
+ st.set_page_config(page_title="Fire Ignition Detector", layout="centered")
10
+
11
+ # ์ƒ๋‹จ ๋กœ๊ณ ์™€ ์ œ๋ชฉ
12
+ st.image("logoall.jpg", use_column_width=True)
13
+ st.markdown("<h2 style='text-align: center;'>ํ™”์žฌ ๋ฐœํ™”์ง€์  ํƒ์ง€๊ธฐ</h2>", unsafe_allow_html=True)
14
+
15
+ # ๋ชจ๋ธ ๋กœ๋“œ
16
+ @st.cache_resource
17
+ def load_model(model_path):
18
+ model = torch.load(model_path, map_location=torch.device('cpu'))
19
+ model.eval()
20
+ return model
21
+
22
+ uploaded_model = st.file_uploader("๐Ÿ”ฅ YOLOv5 ๋ชจ๋ธ(.pt) ํŒŒ์ผ ์—…๋กœ๋“œ", type=["pt"])
23
+ if uploaded_model is not None:
24
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".pt") as tmp_model:
25
+ tmp_model.write(uploaded_model.read())
26
+ model_path = tmp_model.name
27
+ model = load_model(model_path)
28
+ st.success("๋ชจ๋ธ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์—…๋กœ๋“œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
29
+
30
+ # ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ
31
+ uploaded_images = st.file_uploader("๐Ÿ–ผ๏ธ ๋ถ„์„ํ•  ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ (์—ฌ๋Ÿฌ ์žฅ ๊ฐ€๋Šฅ)", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
32
+
33
+ if uploaded_images:
34
+ for img_file in uploaded_images:
35
+ file_bytes = np.asarray(bytearray(img_file.read()), dtype=np.uint8)
36
+ image = cv2.imdecode(file_bytes, 1)
37
+ image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
38
+
39
+ results = model(image_rgb)
40
+
41
+ result_img = results.render()[0]
42
+ st.image(result_img, caption=f"๐Ÿ” ๋ถ„์„ ๊ฒฐ๊ณผ: {img_file.name}", use_column_width=True)
 
 
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
  streamlit
2
  torch
3
- opencv-python-headless
4
  numpy
5
  Pillow
 
1
  streamlit
2
  torch
3
+ opencv-python
4
  numpy
5
  Pillow