engr-abasit commited on
Commit
8bdc567
·
verified ·
1 Parent(s): 94f8f21

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +98 -0
app.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from groq import Groq
4
+ import matplotlib.pyplot as plt
5
+ from fpdf import FPDF
6
+ import io
7
+
8
+ # Set your API key
9
+ os.environ["GROQ_API_KEY"] = "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"
10
+
11
+ # Initialize Groq client
12
+ client = Groq(api_key=os.environ["GROQ_API_KEY"])
13
+
14
+ # App title
15
+ st.title("Cutting Plan Generator")
16
+
17
+ # Input for blank plates
18
+ st.header("Blank Plates Details")
19
+ num_blank_types = st.number_input("Number of Blank Plate Types", min_value=1, step=1, key="num_blank_types")
20
+ blank_data = []
21
+ for i in range(num_blank_types):
22
+ with st.expander(f"Blank Plate {i+1}"):
23
+ blank_width = st.number_input(f"Width (mm) for Blank {i+1}", min_value=0.0, step=0.1, key=f"blank_width_{i}")
24
+ blank_length = st.number_input(f"Length (mm) for Blank {i+1}", min_value=0.0, step=0.1, key=f"blank_length_{i}")
25
+ num_blank_plates = st.number_input(f"Number of Plates for Blank {i+1}", min_value=1, step=1, key=f"num_blank_plates_{i}")
26
+ blank_data.append({"width": blank_width, "length": blank_length, "count": num_blank_plates})
27
+
28
+ # Input for pieces
29
+ st.header("Pieces to be Cut Details")
30
+ num_piece_types = st.number_input("Number of Piece Types", min_value=1, step=1, key="num_piece_types")
31
+ piece_data = []
32
+ for i in range(num_piece_types):
33
+ with st.expander(f"Piece {i+1}"):
34
+ piece_width = st.number_input(f"Width (mm) for Piece {i+1}", min_value=0.0, step=0.1, key=f"piece_width_{i}")
35
+ piece_length = st.number_input(f"Length (mm) for Piece {i+1}", min_value=0.0, step=0.1, key=f"piece_length_{i}")
36
+ num_pieces = st.number_input(f"Number of Pieces for Piece {i+1}", min_value=1, step=1, key=f"num_pieces_{i}")
37
+ piece_data.append({"width": piece_width, "length": piece_length, "count": num_pieces})
38
+
39
+ # Saw cut size and trimming size
40
+ st.header("Other Specifications")
41
+ saw_cut_size = st.number_input("Saw Cut Size (mm)", min_value=0.0, step=0.1, key="saw_cut_size")
42
+ trimming_size = st.number_input("Trimming Size (mm)", min_value=0.0, step=0.1, key="trimming_size")
43
+
44
+ # Priority of blank sizes
45
+ priority = st.selectbox("Priority of Blank Sizes", options=["Smallest First", "Largest First"], key="priority")
46
+
47
+ # Generate Cutting Plan and Sketch
48
+ if st.button("Generate Cutting Plan"):
49
+ total_cut_area = 0
50
+ blank_areas = []
51
+ for blank in blank_data:
52
+ blank_area = (blank["width"] - 2 * trimming_size) * (blank["length"] - 2 * trimming_size) * blank["count"]
53
+ blank_areas.append(blank_area)
54
+
55
+ for piece in piece_data:
56
+ total_cut_area += piece["width"] * piece["length"] * piece["count"]
57
+
58
+ total_blank_area = sum(blank_areas)
59
+ unused_area = total_blank_area - total_cut_area
60
+ usable_area_percentage = (total_cut_area / total_blank_area) * 100
61
+
62
+ st.subheader("Results")
63
+ st.write(f"Total Usable Surface Area: {total_blank_area:.2f} mm²")
64
+ st.write(f"Total Cut Square Area: {total_cut_area:.2f} mm²")
65
+ st.write(f"Total Non-used Square Area: {unused_area:.2f} mm²")
66
+ st.write(f"Percentage of Usable Area: {usable_area_percentage:.2f}%")
67
+
68
+ # Generate sketch
69
+ fig, ax = plt.subplots(figsize=(8, 6))
70
+ for i, blank in enumerate(blank_data):
71
+ ax.add_patch(plt.Rectangle((0, i * (blank["length"] + 10)), blank["width"], blank["length"], edgecolor="blue", facecolor="none", label=f"Blank {i+1}" if i == 0 else ""))
72
+ for j, piece in enumerate(piece_data):
73
+ ax.add_patch(plt.Rectangle((j * (piece["width"] + 5), i * (blank["length"] + 10) + trimming_size), piece["width"], piece["length"], edgecolor="red", facecolor="pink", label=f"Piece {j+1}" if i == 0 else ""))
74
+
75
+ ax.set_xlim(0, max(blank["width"] for blank in blank_data) + 50)
76
+ ax.set_ylim(0, (len(blank_data) * max(blank["length"] for blank in blank_data)) + 100)
77
+ ax.set_title("Cutting Plan Sketch")
78
+ ax.legend(loc="upper right")
79
+ st.pyplot(fig)
80
+
81
+ # Save as PDF
82
+ pdf = FPDF()
83
+ pdf.add_page()
84
+ pdf.set_font("Arial", size=12)
85
+ pdf.cell(200, 10, txt="Cutting Plan Report", ln=True, align="C")
86
+ pdf.cell(200, 10, txt=f"Total Usable Surface Area: {total_blank_area:.2f} mm²", ln=True)
87
+ pdf.cell(200, 10, txt=f"Total Cut Square Area: {total_cut_area:.2f} mm²", ln=True)
88
+ pdf.cell(200, 10, txt=f"Total Non-used Square Area: {unused_area:.2f} mm²", ln=True)
89
+ pdf.cell(200, 10, txt=f"Percentage of Usable Area: {usable_area_percentage:.2f}%", ln=True)
90
+
91
+ pdf_output = io.BytesIO()
92
+ pdf.output(pdf_output)
93
+ st.download_button(
94
+ label="Download Cutting Plan as PDF",
95
+ data=pdf_output.getvalue(),
96
+ file_name="cutting_plan.pdf",
97
+ mime="application/pdf",
98
+ )