Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +42 -44
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -1,44 +1,42 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import torch
|
| 3 |
-
import
|
| 4 |
-
import
|
| 5 |
-
import
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
image =
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 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
|
| 4 |
numpy
|
| 5 |
Pillow
|
|
|
|
| 1 |
streamlit
|
| 2 |
torch
|
| 3 |
+
opencv-python
|
| 4 |
numpy
|
| 5 |
Pillow
|