caveprod/ProcTrans
0
1import pandas as pd
2import os
3import gradio as gr
4
5# -----------------------------
6# Step 1: Identify top 5 keyboard plastics
7# -----------------------------
8def identify_plastics():
9 plastics = [
10 {"Material": "ABS (Acrylonitrile Butadiene Styrene)", "Reason": "Durable, easy to mold, common in keycaps"},
11 {"Material": "PBT (Polybutylene Terephthalate)", "Reason": "Resists wear and shine, used for premium keyboards"},
12 {"Material": "PC (Polycarbonate)", "Reason": "Strong, impact resistant, used for cases and frames"},
13 {"Material": "PVC (Polyvinyl Chloride)", "Reason": "Cost-effective, used in some lower-end plastic parts"},
14 {"Material": "PA (Nylon/Polyamide)", "Reason": "High strength, used for mechanical components"}
15 ]
16 return pd.DataFrame(plastics)
17
18# -----------------------------
19# Step 2–5: Supplier dataset, ranking, and report generation
20# -----------------------------
21def build_and_rank_dataset():
22 data = [
23 ["PlastiTech", "ABS", "$1.5–$2.0/kg", 10, "High", 10, "Texas, USA", 10, "Pellets", "High Volume"],
24 ["FormoChem", "PBT", "$2.0–$2.5/kg", 7, "Premium", 7, "Malaysia", 10, "Pellets", "High Volume"],
25 ["InduPoly", "PC", "$1.8–$2.2/kg", 5, "High", 10, "Brazil", 10, "Sheets", "High Volume"],
26 ["MegaResins", "PVC", "$1.0–$1.5/kg", 3, "Medium", 5, "Mexico", 10, "Blocks", "Medium Volume"],
27 ["StrongBond", "PA", "$2.3–$2.8/kg", 0, "High", 10, "North Carolina, USA", 10, "Pellets", "High Volume"]
28 ]
29
30 cols = [
31 "Supplier Name", "Material", "Material Cost Range", "Material Cost Score",
32 "Material Grade", "Material Grade Score", "Primary Location",
33 "Shipping Distance Score", "Delivery Method", "Capacity Capability"
34 ]
35
36 df = pd.DataFrame(data, columns=cols)
37 # Compute overall score
38 df["Overall Score"] = (df["Material Cost Score"] * 5) + (df["Material Grade Score"] * 3) + (df["Shipping Distance Score"] * 2)
39 return df
40
41# -----------------------------
42# Step 6: Generate and save report
43# -----------------------------
44def generate_report():
45 plastics_df = identify_plastics()
46 suppliers_df = build_and_rank_dataset()
47
48 output_file = "dell_keyboard_plastic_suppliers.xlsx"
49 os.makedirs(".", exist_ok=True)
50
51 with pd.ExcelWriter(output_file, engine='openpyxl') as writer:
52 plastics_df.to_excel(writer, index=False, sheet_name="Plastic Types")
53 suppliers_df.to_excel(writer, index=False, sheet_name="Suppliers")
54
55 return f"✅ Report generated successfully.\n\nFile saved as: {output_file}"
56
57# -----------------------------
58# Optional Gradio UI
59# -----------------------------
60def run_agent():
61 message = generate_report()
62 df = build_and_rank_dataset()
63 return message, df
64
65iface = gr.Interface(
66 fn=run_agent,
67 inputs=[],
68 outputs=[gr.Textbox(lines=4, label="Process Log"), gr.Dataframe(label="Supplier Dataset Snapshot")],
69 title="Dell Keyboard Plastic Procurement Agent",
70 description=(
71 "This agent identifies plastics suitable for Dell keyboards, finds suppliers, "
72 "ranks them based on cost, material grade, and shipping distance, "
73 "and generates an Excel report."
74 ),
75)
76
77if __name__ == "__main__":
78 iface.launch(server_name="0.0.0.0", server_port=7860)