File size: 1,838 Bytes
a681beb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

import subprocess

import streamlit as st
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import subprocess
import os
from PIL import Image
import torch
import sys
#import cv2


def add_logo(logo_path, size=(200, 150)):
    logo = Image.open('logoAI.png')
    logo = logo.resize(size)
    st.image(logo, use_column_width=False)

def run_detection(image_path):
    env = os.environ.copy()
    env['PYTHONPATH'] = '/mount/src/yolo9tr/' 
    
    # Run the detection command
    command = [
        "python", "detect_dual.py",
        "--source", image_path,
        "--img", "640",
        "--device", "cpu",
        "--weights", "models/detect/yolov9tr.pt",
        "--name", "yolov9_c_640_detect",
        "--exist-ok"
    ]
    subprocess.run(command, check=True, env=os.environ)

    # Find the output image
    output_dir = "runs/detect/yolov9_c_640_detect"
    output_image = os.path.join(output_dir, os.path.basename(image_path))
    return output_image

def main():
    st.title("YOLO9tr Object Detection")

    # Add the research center logo at the top of the app
    add_logo("research_center_logo.png")

    uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])

    if uploaded_file is not None:
        image_path = "temp_image.jpg"
        with open(image_path, "wb") as f:
            f.write(uploaded_file.getbuffer())
    else:
        image_path = "United_States_000502.jpg"  # Default image

    st.image(image_path, caption="Image for Detection", use_column_width=True)

    if st.button("Run Detection"):
        with st.spinner("Running detection..."):
            output_image = run_detection(image_path)
        
        # Display the output image
        st.image(output_image, caption="Detection Result", use_column_width=True)

if __name__ == "__main__":
    main()