ZainMalik0925 commited on
Commit
a7694aa
·
verified ·
1 Parent(s): 68095d0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from groq import Groq
4
+ from io import BytesIO
5
+
6
+ # Set up the Groq client
7
+ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
8
+
9
+ # Function to request pattern generation from Groq API
10
+ def get_pattern_from_groq(body_measurements, garment_type):
11
+ # Preparing the prompt for the LLM
12
+ prompt = f"Generate a 2D {garment_type} pattern based on the following body measurements:\n{body_measurements}"
13
+
14
+ # Making a request to Groq's API
15
+ chat_completion = client.chat.completions.create(
16
+ messages=[{"role": "user", "content": prompt}],
17
+ model="llama3-8b-8192",
18
+ stream=False
19
+ )
20
+
21
+ # Get the response content
22
+ return chat_completion.choices[0].message.content
23
+
24
+ # Function to simulate creating a 2D garment pattern (for demo purposes)
25
+ def generate_garment_pattern(body_measurements, garment_type):
26
+ # Here you would typically use the measurements to generate the 2D pattern.
27
+ # We'll simulate this by returning a simple placeholder pattern.
28
+ pattern = f"2D {garment_type} Pattern based on measurements:\n{body_measurements}"
29
+ return pattern
30
+
31
+ # Main Streamlit app UI
32
+ def main():
33
+ st.title("Garment Pattern Design Tool")
34
+
35
+ # Select garment type
36
+ garment_type = st.selectbox("Select Garment Type", ["Top Body Garment", "Bottom Garment"])
37
+
38
+ # Collect body measurements based on garment type
39
+ st.header(f"Enter Measurements for {garment_type}")
40
+
41
+ body_measurements = {}
42
+
43
+ if garment_type == "Top Body Garment":
44
+ body_measurements['Chest'] = st.number_input('Chest (in cm)', min_value=0, step=1)
45
+ body_measurements['Waist'] = st.number_input('Waist (in cm)', min_value=0, step=1)
46
+ body_measurements['Neck'] = st.number_input('Neck (in cm)', min_value=0, step=1)
47
+ body_measurements['Height'] = st.number_input('Height (in cm)', min_value=0, step=1)
48
+
49
+ elif garment_type == "Bottom Garment":
50
+ body_measurements['Waist'] = st.number_input('Waist (in cm)', min_value=0, step=1)
51
+ body_measurements['Hip'] = st.number_input('Hip (in cm)', min_value=0, step=1)
52
+ body_measurements['Inseam'] = st.number_input('Inseam (in cm)', min_value=0, step=1)
53
+ body_measurements['Height'] = st.number_input('Height (in cm)', min_value=0, step=1)
54
+
55
+ body_measurements_str = "\n".join([f"{key}: {value}" for key, value in body_measurements.items()])
56
+
57
+ if st.button("Generate Pattern"):
58
+ if all(value > 0 for value in body_measurements.values()):
59
+ # Fetch pattern from Groq LLM
60
+ st.write("Generating pattern...")
61
+ pattern = get_pattern_from_groq(body_measurements_str, garment_type)
62
+
63
+ # Simulate the 2D pattern generation (you can replace this with actual pattern generation logic)
64
+ pattern_output = generate_garment_pattern(body_measurements_str, garment_type)
65
+
66
+ # Display the result
67
+ st.subheader(f"Generated 2D {garment_type} Pattern:")
68
+ st.text(pattern_output)
69
+
70
+ # Simulating file download
71
+ buffer = BytesIO()
72
+ buffer.write(pattern_output.encode())
73
+ buffer.seek(0)
74
+
75
+ st.download_button(
76
+ label="Download Garment Pattern",
77
+ data=buffer,
78
+ file_name=f"{garment_type.lower().replace(' ', '_')}_pattern.txt",
79
+ mime="text/plain"
80
+ )
81
+ else:
82
+ st.error("Please enter valid measurements for all fields.")
83
+
84
+ if __name__ == "__main__":
85
+ main()