Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import pipeline | |
| # Load pretrained DETR model for object detection | |
| detection_model = pipeline("object-detection", model="facebook/detr-resnet-50") | |
| # Function to assess vehicle damage | |
| def assess_vehicle_damage(image): | |
| try: | |
| # Use the model to predict object locations and labels | |
| predictions = detection_model(image) | |
| # Format results to highlight detected objects and potential damage | |
| report = "🔍 Vehicle Damage Assessment:\n" | |
| for pred in predictions: | |
| label = pred['label'] | |
| score = pred['score'] | |
| box = pred['box'] | |
| report += ( | |
| f"- {label} detected with confidence {score:.2f}.\n" | |
| f" Location: (X: {box['xmin']:.1f}, Y: {box['ymin']:.1f}, " | |
| f"Width: {box['xmax'] - box['xmin']:.1f}, Height: {box['ymax'] - box['ymin']:.1f})\n" | |
| ) | |
| # Add general recommendations based on detected objects | |
| report += "\n💡 Recommendations:\n" | |
| if any("car" in pred['label'].lower() for pred in predictions): | |
| report += "- Inspect detected areas closely for damage severity.\n" | |
| else: | |
| report += "- No visible vehicle parts detected. Please upload a clearer image.\n" | |
| return report | |
| except Exception as e: | |
| return f"Error processing the image: {e}" | |
| # Gradio interface | |
| interface = gr.Interface( | |
| fn=assess_vehicle_damage, | |
| inputs=gr.Image(type="file", label="Upload Vehicle Image"), | |
| outputs=gr.Textbox(label="Damage Assessment Report"), | |
| title="Vehicle Damage Assessor", | |
| description=( | |
| "Upload an image of a vehicle to detect damaged parts and get an assessment report. " | |
| "The app uses advanced AI models to identify objects and predict potential issues." | |
| ), | |
| allow_flagging="never" | |
| ) | |
| if __name__ == "__main__": | |
| interface.launch() | |