File size: 3,560 Bytes
51d1b47
74e46f4
 
 
51d1b47
74e46f4
 
 
51d1b47
74e46f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e9b0c3c
51d1b47
 
74e46f4
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import gradio as gr
from transformers import pipeline
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas

# Load a pre-trained image classification model from Hugging Face
# Replace with a fine-tuned model if available
home_inspector = pipeline("image-classification", model="google/vit-base-patch16-224")

# Function to analyze the uploaded image
def inspect_home(image):
    # Analyze the image using the Hugging Face model
    results = home_inspector(image)
    
    # Format the results
    detected_issues = {result["label"]: round(result["score"], 2) for result in results}
    
    # Generate repair suggestions based on detected issues
    suggestions = []
    for issue in detected_issues:
        suggestion = f"For {issue}, consider inspecting the area closely and consulting a professional if necessary."
        suggestions.append(suggestion)
    
    # Generate a PDF report
    generate_report(detected_issues, suggestions)
    
    # Return results and suggestions
    return detected_issues, suggestions

# Function to generate a PDF report
def generate_report(issues, suggestions, filename="home_inspection_report.pdf"):
    c = canvas.Canvas(filename, pagesize=letter)
    
    # Add a title
    c.setFont("Helvetica-Bold", 16)
    c.drawString(100, 750, "Home Inspection Report")
    
    # Add a subtitle
    c.setFont("Helvetica", 12)
    c.drawString(100, 730, "AI-Powered Home Inspector")
    
    # Add issues and suggestions
    y = 700
    for issue, suggestion in zip(issues, suggestions):
        c.setFont("Helvetica-Bold", 12)
        c.drawString(100, y, f"Issue: {issue} (Confidence: {issues[issue]})")
        c.setFont("Helvetica", 10)
        c.drawString(100, y - 20, f"Suggestion: {suggestion}")
        y -= 40
    
    # Save the PDF
    c.save()

# Custom CSS for a modern blue and silver interface
custom_css = """
body {
    background: linear-gradient(135deg, #1e3c72, #2a5298);
    color: white;
    font-family: 'Helvetica', sans-serif;
}
.gradio-container {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.gradio-input, .gradio-output {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 5px;
    padding: 10px;
    color: white;
}
.gradio-button {
    background: #4a90e2;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s ease;
}
.gradio-button:hover {
    background: #357abd;
}
"""

# Gradio interface
with gr.Blocks(css=custom_css) as demo:
    gr.Markdown("# ๐Ÿ  AI-Powered Home Inspector")
    gr.Markdown("Upload a photo of your home, and the AI will detect issues and provide repair suggestions.")
    
    with gr.Row():
        with gr.Column():
            image_input = gr.Image(label="Upload a Photo", type="pil")
            inspect_button = gr.Button("Inspect Home", variant="primary")
        
        with gr.Column():
            issues_output = gr.Label(label="Detected Issues")
            suggestions_output = gr.Textbox(label="Repair Suggestions", lines=5)
    
    # Link the button to the function
    inspect_button.click(
        fn=inspect_home,
        inputs=image_input,
        outputs=[issues_output, suggestions_output]
    )
    
    gr.Markdown("### Report Generated")
    gr.Markdown("A very detailed PDF report has been saved as `home_inspection_report.pdf`.")

# Launch the app
demo.launch()