Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import cv2
|
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
import gradio as gr
|
|
|
|
| 5 |
|
| 6 |
# Function to calculate materials based on blueprint dimensions
|
| 7 |
def calculate_materials_from_dimensions(wall_area, foundation_area):
|
|
@@ -27,8 +28,14 @@ def calculate_materials_from_dimensions(wall_area, foundation_area):
|
|
| 27 |
|
| 28 |
# Function to process the blueprint and extract dimensions
|
| 29 |
def process_blueprint(image_path):
|
| 30 |
-
# Open the image
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
if image is None:
|
| 33 |
raise ValueError("Could not load the image")
|
| 34 |
|
|
@@ -86,12 +93,12 @@ def process_blueprint(image_path):
|
|
| 86 |
# Set up Gradio interface
|
| 87 |
interface = gr.Interface(
|
| 88 |
fn=process_blueprint,
|
| 89 |
-
inputs=gr.
|
| 90 |
outputs=gr.JSON(label="Material Estimates"),
|
| 91 |
title="Blueprint Material Estimator",
|
| 92 |
-
description="Upload a blueprint image to estimate construction materials."
|
| 93 |
)
|
| 94 |
|
| 95 |
# Launch the interface
|
| 96 |
if __name__ == "__main__":
|
| 97 |
-
interface.launch(share=False)
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
| 4 |
import gradio as gr
|
| 5 |
+
from pdf2image import convert_from_path # Import the PDF-to-image conversion library
|
| 6 |
|
| 7 |
# Function to calculate materials based on blueprint dimensions
|
| 8 |
def calculate_materials_from_dimensions(wall_area, foundation_area):
|
|
|
|
| 28 |
|
| 29 |
# Function to process the blueprint and extract dimensions
|
| 30 |
def process_blueprint(image_path):
|
| 31 |
+
# Open the image (supporting both image and PDF inputs)
|
| 32 |
+
if image_path.lower().endswith(".pdf"):
|
| 33 |
+
# Convert the PDF to an image (first page)
|
| 34 |
+
images = convert_from_path(image_path, first_page=1, last_page=1)
|
| 35 |
+
image = np.array(images[0])
|
| 36 |
+
else:
|
| 37 |
+
# Open the image file
|
| 38 |
+
image = cv2.imread(image_path)
|
| 39 |
if image is None:
|
| 40 |
raise ValueError("Could not load the image")
|
| 41 |
|
|
|
|
| 93 |
# Set up Gradio interface
|
| 94 |
interface = gr.Interface(
|
| 95 |
fn=process_blueprint,
|
| 96 |
+
inputs=gr.File(label="Upload Blueprint (Image or PDF)", type="filepath"), # Support both image and PDF files
|
| 97 |
outputs=gr.JSON(label="Material Estimates"),
|
| 98 |
title="Blueprint Material Estimator",
|
| 99 |
+
description="Upload a blueprint image or PDF to estimate construction materials."
|
| 100 |
)
|
| 101 |
|
| 102 |
# Launch the interface
|
| 103 |
if __name__ == "__main__":
|
| 104 |
+
interface.launch(share=False)
|