|
import gradio as gr |
|
from transformers import pipeline |
|
from reportlab.lib.pagesizes import letter |
|
from reportlab.pdfgen import canvas |
|
|
|
|
|
|
|
home_inspector = pipeline("image-classification", model="google/vit-base-patch16-224") |
|
|
|
|
|
def inspect_home(image): |
|
|
|
results = home_inspector(image) |
|
|
|
|
|
detected_issues = {result["label"]: round(result["score"], 2) for result in results} |
|
|
|
|
|
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_report(detected_issues, suggestions) |
|
|
|
|
|
return detected_issues, suggestions |
|
|
|
|
|
def generate_report(issues, suggestions, filename="home_inspection_report.pdf"): |
|
c = canvas.Canvas(filename, pagesize=letter) |
|
|
|
|
|
c.setFont("Helvetica-Bold", 16) |
|
c.drawString(100, 750, "Home Inspection Report") |
|
|
|
|
|
c.setFont("Helvetica", 12) |
|
c.drawString(100, 730, "AI-Powered Home Inspector") |
|
|
|
|
|
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 |
|
|
|
|
|
c.save() |
|
|
|
|
|
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; |
|
} |
|
""" |
|
|
|
|
|
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) |
|
|
|
|
|
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`.") |
|
|
|
|
|
demo.launch() |