GeminiAi commited on
Commit
51d1b47
·
verified ·
1 Parent(s): 131437d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +114 -0
app.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from reportlab.lib.pagesizes import letter
4
+ from reportlab.pdfgen import canvas
5
+
6
+ # Load a pre-trained image classification model from Hugging Face
7
+ # Replace with a fine-tuned model if available
8
+ home_inspector = pipeline("image-classification", model="google/vit-base-patch16-224")
9
+
10
+ # Function to analyze the uploaded image
11
+ def inspect_home(image):
12
+ # Analyze the image using the Hugging Face model
13
+ results = home_inspector(image)
14
+
15
+ # Format the results
16
+ detected_issues = {result["label"]: round(result["score"], 2) for result in results}
17
+
18
+ # Generate repair suggestions based on detected issues
19
+ suggestions = []
20
+ for issue in detected_issues:
21
+ suggestion = f"For {issue}, consider inspecting the area closely and consulting a professional if necessary."
22
+ suggestions.append(suggestion)
23
+
24
+ # Generate a PDF report
25
+ generate_report(detected_issues, suggestions)
26
+
27
+ # Return results and suggestions
28
+ return detected_issues, suggestions
29
+
30
+ # Function to generate a PDF report
31
+ def generate_report(issues, suggestions, filename="home_inspection_report.pdf"):
32
+ c = canvas.Canvas(filename, pagesize=letter)
33
+
34
+ # Add a title
35
+ c.setFont("Helvetica-Bold", 16)
36
+ c.drawString(100, 750, "Home Inspection Report")
37
+
38
+ # Add a subtitle
39
+ c.setFont("Helvetica", 12)
40
+ c.drawString(100, 730, "AI-Powered Home Inspector")
41
+
42
+ # Add issues and suggestions
43
+ y = 700
44
+ for issue, suggestion in zip(issues, suggestions):
45
+ c.setFont("Helvetica-Bold", 12)
46
+ c.drawString(100, y, f"Issue: {issue} (Confidence: {issues[issue]})")
47
+ c.setFont("Helvetica", 10)
48
+ c.drawString(100, y - 20, f"Suggestion: {suggestion}")
49
+ y -= 40
50
+
51
+ # Save the PDF
52
+ c.save()
53
+
54
+ # Custom CSS for a modern blue and silver interface
55
+ custom_css = """
56
+ body {
57
+ background: linear-gradient(135deg, #1e3c72, #2a5298);
58
+ color: white;
59
+ font-family: 'Helvetica', sans-serif;
60
+ }
61
+ .gradio-container {
62
+ background: rgba(255, 255, 255, 0.1);
63
+ border-radius: 10px;
64
+ padding: 20px;
65
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
66
+ }
67
+ .gradio-input, .gradio-output {
68
+ background: rgba(255, 255, 255, 0.2);
69
+ border: 1px solid rgba(255, 255, 255, 0.3);
70
+ border-radius: 5px;
71
+ padding: 10px;
72
+ color: white;
73
+ }
74
+ .gradio-button {
75
+ background: #4a90e2;
76
+ color: white;
77
+ border: none;
78
+ border-radius: 5px;
79
+ padding: 10px 20px;
80
+ font-size: 16px;
81
+ cursor: pointer;
82
+ transition: background 0.3s ease;
83
+ }
84
+ .gradio-button:hover {
85
+ background: #357abd;
86
+ }
87
+ """
88
+
89
+ # Gradio interface
90
+ with gr.Blocks(css=custom_css) as demo:
91
+ gr.Markdown("# 🏠 AI-Powered Home Inspector")
92
+ gr.Markdown("Upload a photo of your home, and the AI will detect issues and provide repair suggestions.")
93
+
94
+ with gr.Row():
95
+ with gr.Column():
96
+ image_input = gr.Image(label="Upload a Photo", type="pil")
97
+ inspect_button = gr.Button("Inspect Home", variant="primary")
98
+
99
+ with gr.Column():
100
+ issues_output = gr.Label(label="Detected Issues")
101
+ suggestions_output = gr.Textbox(label="Repair Suggestions", lines=5)
102
+
103
+ # Link the button to the function
104
+ inspect_button.click(
105
+ fn=inspect_home,
106
+ inputs=image_input,
107
+ outputs=[issues_output, suggestions_output]
108
+ )
109
+
110
+ gr.Markdown("### Report Generated")
111
+ gr.Markdown("A detailed PDF report has been saved as `home_inspection_report.pdf`.")
112
+
113
+ # Launch the app
114
+ demo.launch()