File size: 4,562 Bytes
a7694aa
00b4d59
 
a7694aa
 
00b4d59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7694aa
 
 
00b4d59
 
 
a7694aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
00b4d59
 
 
 
a7694aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
00b4d59
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import os
import sys
import subprocess
import streamlit as st

# Check if 'groq' is installed, and if not, prompt the user to install it
def check_groq_installed():
    try:
        import groq
        return True
    except ImportError:
        return False

# Check Python version compatibility
def check_python_version():
    required_version = (3, 6)  # Minimum required Python version
    current_version = sys.version_info
    if current_version < required_version:
        return False
    return True

# Check if the Groq client is correctly initialized
def check_groq_client():
    try:
        from groq import Groq
        # Try initializing the Groq client with the provided API key
        client = Groq(api_key="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")
        return True
    except Exception as e:
        print(f"Error initializing Groq client: {e}")
        return False

# Run all checks before proceeding
def run_checks():
    # Check if groq is installed
    if not check_groq_installed():
        st.error("Groq module is not installed. Please install it using 'pip install groq'.")
        return False
    
    # Check if Python version is compatible
    if not check_python_version():
        st.error("Python version 3.6 or higher is required. Please upgrade your Python.")
        return False
    
    # Check if the Groq client can be initialized
    if not check_groq_client():
        st.error("Failed to initialize Groq client. Check your API key and the Groq module installation.")
        return False
    
    return True

# Function to request pattern generation from Groq API
def get_pattern_from_groq(body_measurements, garment_type):
    from groq import Groq
    client = Groq(api_key="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")

    # Preparing the prompt for the LLM
    prompt = f"Generate a 2D {garment_type} pattern based on the following body measurements:\n{body_measurements}"
    
    # Making a request to Groq's API
    chat_completion = client.chat.completions.create(
        messages=[{"role": "user", "content": prompt}],
        model="llama3-8b-8192",
        stream=False
    )
    
    # Get the response content
    return chat_completion.choices[0].message.content

# Function to simulate creating a 2D garment pattern (for demo purposes)
def generate_garment_pattern(body_measurements, garment_type):
    # Here you would typically use the measurements to generate the 2D pattern.
    # We'll simulate this by returning a simple placeholder pattern.
    pattern = f"2D {garment_type} Pattern based on measurements:\n{body_measurements}"
    return pattern

# Main Streamlit app UI
def main():
    # Perform pre-execution checks
    if not run_checks():
        return

    st.title("Garment Pattern Design Tool")
    
    # Select garment type
    garment_type = st.selectbox("Select Garment Type", ["Top Body Garment", "Bottom Garment"])
    
    # Collect body measurements based on garment type
    st.header(f"Enter Measurements for {garment_type}")
    
    body_measurements = {}
    
    if garment_type == "Top Body Garment":
        body_measurements['Chest'] = st.number_input('Chest (in cm)', min_value=0, step=1)
        body_measurements['Waist'] = st.number_input('Waist (in cm)', min_value=0, step=1)
        body_measurements['Neck'] = st.number_input('Neck (in cm)', min_value=0, step=1)
        body_measurements['Height'] = st.number_input('Height (in cm)', min_value=0, step=1)
    
    elif garment_type == "Bottom Garment":
        body_measurements['Waist'] = st.number_input('Waist (in cm)', min_value=0, step=1)
        body_measurements['Hip'] = st.number_input('Hip (in cm)', min_value=0, step=1)
        body_measurements['Inseam'] = st.number_input('Inseam (in cm)', min_value=0, step=1)
        body_measurements['Height'] = st.number_input('Height (in cm)', min_value=0, step=1)
    
    body_measurements_str = "\n".join([f"{key}: {value}" for key, value in body_measurements.items()])
    
    if st.button("Generate Pattern"):
        if all(value > 0 for value in body_measurements.values()):
            # Fetch pattern from Groq LLM
            st.write("Generating pattern...")
            pattern = get_pattern_from_groq(body_measurements_str, garment_type)
            
            # Simulate the 2D pattern generation (you can replace this with actual pattern generation logic)
            pattern_output = generate_garment_pattern(body_measurements_str, garment_type)
            
            # Display the result