File size: 3,389 Bytes
9d15feb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pandas as pd
import os
import gradio as gr

# -----------------------------
# Step 1: Identify top 5 keyboard plastics
# -----------------------------
def identify_plastics():
    plastics = [
        {"Material": "ABS (Acrylonitrile Butadiene Styrene)", "Reason": "Durable, easy to mold, common in keycaps"},
        {"Material": "PBT (Polybutylene Terephthalate)", "Reason": "Resists wear and shine, used for premium keyboards"},
        {"Material": "PC (Polycarbonate)", "Reason": "Strong, impact resistant, used for cases and frames"},
        {"Material": "PVC (Polyvinyl Chloride)", "Reason": "Cost-effective, used in some lower-end plastic parts"},
        {"Material": "PA (Nylon/Polyamide)", "Reason": "High strength, used for mechanical components"}
    ]
    return pd.DataFrame(plastics)

# -----------------------------
# Step 2–5: Supplier dataset, ranking, and report generation
# -----------------------------
def build_and_rank_dataset():
    data = [
        ["PlastiTech", "ABS", "$1.5–$2.0/kg", 10, "High", 10, "Texas, USA", 10, "Pellets", "High Volume"],
        ["FormoChem", "PBT", "$2.0–$2.5/kg", 7, "Premium", 7, "Malaysia", 10, "Pellets", "High Volume"],
        ["InduPoly", "PC", "$1.8–$2.2/kg", 5, "High", 10, "Brazil", 10, "Sheets", "High Volume"],
        ["MegaResins", "PVC", "$1.0–$1.5/kg", 3, "Medium", 5, "Mexico", 10, "Blocks", "Medium Volume"],
        ["StrongBond", "PA", "$2.3–$2.8/kg", 0, "High", 10, "North Carolina, USA", 10, "Pellets", "High Volume"]
    ]

    cols = [
        "Supplier Name", "Material", "Material Cost Range", "Material Cost Score",
        "Material Grade", "Material Grade Score", "Primary Location",
        "Shipping Distance Score", "Delivery Method", "Capacity Capability"
    ]

    df = pd.DataFrame(data, columns=cols)
    # Compute overall score
    df["Overall Score"] = (df["Material Cost Score"] * 5) + (df["Material Grade Score"] * 3) + (df["Shipping Distance Score"] * 2)
    return df

# -----------------------------
# Step 6: Generate and save report
# -----------------------------
def generate_report():
    plastics_df = identify_plastics()
    suppliers_df = build_and_rank_dataset()

    output_file = "dell_keyboard_plastic_suppliers.xlsx"
    os.makedirs(".", exist_ok=True)

    with pd.ExcelWriter(output_file, engine='openpyxl') as writer:
        plastics_df.to_excel(writer, index=False, sheet_name="Plastic Types")
        suppliers_df.to_excel(writer, index=False, sheet_name="Suppliers")

    return f"βœ… Report generated successfully.\n\nFile saved as: {output_file}"

# -----------------------------
# Optional Gradio UI
# -----------------------------
def run_agent():
    message = generate_report()
    df = build_and_rank_dataset()
    return message, df

iface = gr.Interface(
    fn=run_agent,
    inputs=[],
    outputs=[gr.Textbox(lines=4, label="Process Log"), gr.Dataframe(label="Supplier Dataset Snapshot")],
    title="Dell Keyboard Plastic Procurement Agent",
    description=(
        "This agent identifies plastics suitable for Dell keyboards, finds suppliers, "
        "ranks them based on cost, material grade, and shipping distance, "
        "and generates an Excel report."
    ),
)

if __name__ == "__main__":
    iface.launch(server_name="0.0.0.0", server_port=7860)