meraj12 commited on
Commit
fe2d46a
·
verified ·
1 Parent(s): c434efa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -60
app.py CHANGED
@@ -1,65 +1,27 @@
1
  import streamlit as st
2
- import cv2
3
- import numpy as np
4
- from ultralytics import YOLO
5
- from PIL import Image
6
- import tempfile
7
 
8
- # Load YOLO Model
9
- model = YOLO('yolov8n.pt')
10
 
11
- st.title("Object & House Size Estimation")
12
- st.write("Upload an image to detect objects, house size, and wall dimensions.")
13
-
14
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- if uploaded_file is not None:
17
- with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
18
- temp_file.write(uploaded_file.read())
19
- image_path = temp_file.name
20
-
21
- image = cv2.imread(image_path)
22
- results = model(image)
23
 
24
- object_sizes = {}
25
- house_size = None
26
- wall_size = None
27
-
28
- for r in results:
29
- for box in r.boxes:
30
- x1, y1, x2, y2 = map(int, box.xyxy[0])
31
- label = model.names[int(box.cls[0])]
32
- width = abs(x2 - x1)
33
- height = abs(y2 - y1)
34
- object_sizes[label] = (width, height)
35
- cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
36
- cv2.putText(image, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
37
-
38
- if "house" in label.lower():
39
- house_size = (width, height)
40
- elif "wall" in label.lower():
41
- wall_size = (width, height)
42
-
43
- st.image(image, caption="Detected Objects", use_column_width=True)
44
-
45
- reference_object = "door" # Assume a known object for scaling
46
- reference_size_inches = 80 # Example: Assume a door is 80 inches tall
47
- if reference_object in object_sizes:
48
- ref_width_pixels = object_sizes[reference_object][0]
49
- scale = reference_size_inches / ref_width_pixels
50
- for obj, (w, h) in object_sizes.items():
51
- object_sizes[obj] = (round(w * scale, 2), round(h * scale, 2))
52
-
53
- if house_size:
54
- house_size = (round(house_size[0] * scale, 2), round(house_size[1] * scale, 2))
55
- if wall_size:
56
- wall_size = (round(wall_size[0] * scale, 2), round(wall_size[1] * scale, 2))
57
-
58
- st.write("Predicted Object Sizes (in inches):")
59
- for obj, size in object_sizes.items():
60
- st.write(f"{obj}: Width = {size[0]} inches, Height = {size[1]} inches")
61
-
62
- if house_size:
63
- st.write(f"House Size: Width = {house_size[0]} inches, Height = {house_size[1]} inches")
64
- if wall_size:
65
- st.write(f"Wall Size: Width = {wall_size[0]} inches, Height = {wall_size[1]} inches")
 
1
  import streamlit as st
 
 
 
 
 
2
 
3
+ # Video URL (Replace with your own video link)
4
+ video_url = "https://www.example.com/path-to-your-video.mp4"
5
 
6
+ # Embed video using HTML & CSS
7
+ video_html = f"""
8
+ <style>
9
+ video {{
10
+ position: fixed;
11
+ right: 0;
12
+ bottom: 0;
13
+ min-width: 100%;
14
+ min-height: 100%;
15
+ z-index: -1;
16
+ }}
17
+ </style>
18
+ <video autoplay loop muted>
19
+ <source src="{video_url}" type="video/mp4">
20
+ </video>
21
+ """
22
 
23
+ # Display the video background
24
+ st.markdown(video_html, unsafe_allow_html=True)
 
 
 
 
 
25
 
26
+ st.title("Object & House Size Estimation")
27
+ st.write("Upload an image to detect objects, house size, and wall dimensions.")