Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load pretrained DETR model for object detection
|
5 |
+
detection_model = pipeline("object-detection", model="facebook/detr-resnet-50")
|
6 |
+
|
7 |
+
# Function to assess vehicle damage
|
8 |
+
def assess_vehicle_damage(image):
|
9 |
+
try:
|
10 |
+
# Use the model to predict object locations and labels
|
11 |
+
predictions = detection_model(image)
|
12 |
+
|
13 |
+
# Format results to highlight detected objects and potential damage
|
14 |
+
report = "🔍 Vehicle Damage Assessment:\n"
|
15 |
+
for pred in predictions:
|
16 |
+
label = pred['label']
|
17 |
+
score = pred['score']
|
18 |
+
box = pred['box']
|
19 |
+
report += (
|
20 |
+
f"- {label} detected with confidence {score:.2f}.\n"
|
21 |
+
f" Location: (X: {box['xmin']:.1f}, Y: {box['ymin']:.1f}, "
|
22 |
+
f"Width: {box['xmax'] - box['xmin']:.1f}, Height: {box['ymax'] - box['ymin']:.1f})\n"
|
23 |
+
)
|
24 |
+
|
25 |
+
# Add general recommendations based on detected objects
|
26 |
+
report += "\n💡 Recommendations:\n"
|
27 |
+
if any("car" in pred['label'].lower() for pred in predictions):
|
28 |
+
report += "- Inspect detected areas closely for damage severity.\n"
|
29 |
+
else:
|
30 |
+
report += "- No visible vehicle parts detected. Please upload a clearer image.\n"
|
31 |
+
|
32 |
+
return report
|
33 |
+
except Exception as e:
|
34 |
+
return f"Error processing the image: {e}"
|
35 |
+
|
36 |
+
# Gradio interface
|
37 |
+
interface = gr.Interface(
|
38 |
+
fn=assess_vehicle_damage,
|
39 |
+
inputs=gr.Image(type="file", label="Upload Vehicle Image"),
|
40 |
+
outputs=gr.Textbox(label="Damage Assessment Report"),
|
41 |
+
title="Vehicle Damage Assessor",
|
42 |
+
description=(
|
43 |
+
"Upload an image of a vehicle to detect damaged parts and get an assessment report. "
|
44 |
+
"The app uses advanced AI models to identify objects and predict potential issues."
|
45 |
+
),
|
46 |
+
allow_flagging="never"
|
47 |
+
)
|
48 |
+
|
49 |
+
if __name__ == "__main__":
|
50 |
+
interface.launch()
|