Anujagr/mcapro
0
1import gradio as gr2from PIL import Image3 4# Simulate AI analysis of uploaded image5def analyze_image(image):6 # Fake detection logic (you can replace with real AI model later)7 detected_parts = [8 {"Part": "Headlight", "Condition": "Reusable", "Estimated Price": 800},9 {"Part": "Grill", "Condition": "Reusable", "Estimated Price": 500},10 {"Part": "Bumper", "Condition": "Damaged", "Estimated Price": 0},11 ]12 return detected_parts, image13 14# Generate a dynamic reuse suggestion based on updated table15def generate_dynamic_message(part_data):16 reusable_parts = [p["Part"] for p in part_data if p["Condition"] == "Reusable"]17 damaged_parts = [p["Part"] for p in part_data if p["Condition"] == "Damaged"]18 19 message = "โป Reuse Suggestion:\n"20 if reusable_parts:21 message += f"- You can reuse or resell: **{', '.join(reusable_parts)}**.\n"22 if damaged_parts:23 message += f"- Consider recycling or discarding: **{', '.join(damaged_parts)}**.\n"24 25 return message26 27# Gradio UI28with gr.Blocks() as demo:29 gr.Markdown("## ๐ Repair & Resell AI\nUpload an image of a damaged item to analyze reusable parts and set resale prices.")30 31 with gr.Row():32 image_input = gr.Image(type="pil", label="๐ท Upload Damaged Product Image")33 analyze_btn = gr.Button("๐ Analyze")34 35 part_table = gr.Dataframe(headers=["Part", "Condition", "Estimated Price"], interactive=True)36 suggestion_output = gr.Textbox(label="๐ก AI-Powered Reuse Suggestion", lines=4)37 image_display = gr.Image(label="๐ธ Uploaded Product Image")38 update_btn = gr.Button("๐ Update Suggestion After Editing Prices")39 40 # On image analysis41 analyze_btn.click(fn=analyze_image, inputs=image_input, outputs=[part_table, image_display])42 43 # On price or condition update44 update_btn.click(fn=generate_dynamic_message, inputs=part_table, outputs=suggestion_output)45 46demo.launch()47 