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

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +36 -30
  2. requirements.txt +2 -4
app.py CHANGED
@@ -1,38 +1,44 @@
1
- import gradio as gr
2
  import torch
3
  import cv2
4
- import numpy as np
5
- from PIL import Image
6
  import tempfile
7
- import requests
8
  import os
9
-
10
- # ๋ชจ๋ธ ๋‹ค์šด๋กœ๋“œ (Google Drive ๋˜๋Š” ์™ธ๋ถ€ URL์—์„œ best.pt๋ฅผ ๋กœ๋“œ)
11
- MODEL_URL = "https://huggingface.co/Daebin/fire-ignition-detector/resolve/main/best.pt"
12
 
13
  @st.cache_resource
14
- def load_model():
15
- with tempfile.NamedTemporaryFile(delete=False, suffix=".pt") as tmp:
16
- tmp.write(requests.get(MODEL_URL).content)
17
- tmp_path = tmp.name
18
- model = torch.hub.load("ultralytics/yolov5", "custom", path=tmp_path, force_reload=True)
19
- return model
20
-
21
- model = load_model()
22
-
23
- def detect_fire(image):
24
- image = Image.fromarray(image)
25
- results = model(image)
26
- results.render()
27
- return Image.fromarray(results.ims[0])
28
-
29
- iface = gr.Interface(
30
- fn=detect_fire,
31
- inputs=gr.Image(type="numpy"),
32
- outputs=gr.Image(type="pil"),
33
- title="Fire Ignition Detector",
34
- description="Upload an image to detect ignition point using YOLOv5."
35
- )
 
 
 
 
 
 
 
 
 
36
 
37
  if __name__ == "__main__":
38
- iface.launch()
 
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()
requirements.txt CHANGED
@@ -1,7 +1,5 @@
 
1
  torch
2
- torchvision
3
- opencv-python
4
  numpy
5
  Pillow
6
- requests
7
- gradio
 
1
+ streamlit
2
  torch
3
+ opencv-python-headless
 
4
  numpy
5
  Pillow