Download app.py from caveprod/ProcTrans: direct link, hf CLI and curl.
- Browser
- Download file 3.39 kB
-
https://huggingface.co/spaces/caveprod/ProcTrans/resolve/main/app.py
- Command line
-
hf download hf://spaces/caveprod/ProcTrans/app.py
-
curl -L -o app.py https://huggingface.co/spaces/caveprod/ProcTrans/resolve/main/app.py
3.39 kB
| 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) |