ZainMalik0925 commited on
Commit
00b4d59
·
verified ·
1 Parent(s): 043429c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -23
app.py CHANGED
@@ -1,13 +1,59 @@
1
  import os
 
 
2
  import streamlit as st
3
- from io import BytesIO
4
- from groq import Groq
5
 
6
- # Set up the Groq client with your API key directly
7
- client = Groq(api_key="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")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
@@ -30,6 +76,10 @@ def generate_garment_pattern(body_measurements, garment_type):
30
 
31
  # Main Streamlit app UI
32
  def main():
 
 
 
 
33
  st.title("Garment Pattern Design Tool")
34
 
35
  # Select garment type
@@ -64,22 +114,4 @@ def main():
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()
 
1
  import os
2
+ import sys
3
+ import subprocess
4
  import streamlit as st
 
 
5
 
6
+ # Check if 'groq' is installed, and if not, prompt the user to install it
7
+ def check_groq_installed():
8
+ try:
9
+ import groq
10
+ return True
11
+ except ImportError:
12
+ return False
13
+
14
+ # Check Python version compatibility
15
+ def check_python_version():
16
+ required_version = (3, 6) # Minimum required Python version
17
+ current_version = sys.version_info
18
+ if current_version < required_version:
19
+ return False
20
+ return True
21
+
22
+ # Check if the Groq client is correctly initialized
23
+ def check_groq_client():
24
+ try:
25
+ from groq import Groq
26
+ # Try initializing the Groq client with the provided API key
27
+ client = Groq(api_key="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")
28
+ return True
29
+ except Exception as e:
30
+ print(f"Error initializing Groq client: {e}")
31
+ return False
32
+
33
+ # Run all checks before proceeding
34
+ def run_checks():
35
+ # Check if groq is installed
36
+ if not check_groq_installed():
37
+ st.error("Groq module is not installed. Please install it using 'pip install groq'.")
38
+ return False
39
+
40
+ # Check if Python version is compatible
41
+ if not check_python_version():
42
+ st.error("Python version 3.6 or higher is required. Please upgrade your Python.")
43
+ return False
44
+
45
+ # Check if the Groq client can be initialized
46
+ if not check_groq_client():
47
+ st.error("Failed to initialize Groq client. Check your API key and the Groq module installation.")
48
+ return False
49
+
50
+ return True
51
 
52
  # Function to request pattern generation from Groq API
53
  def get_pattern_from_groq(body_measurements, garment_type):
54
+ from groq import Groq
55
+ client = Groq(api_key="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")
56
+
57
  # Preparing the prompt for the LLM
58
  prompt = f"Generate a 2D {garment_type} pattern based on the following body measurements:\n{body_measurements}"
59
 
 
76
 
77
  # Main Streamlit app UI
78
  def main():
79
+ # Perform pre-execution checks
80
+ if not run_checks():
81
+ return
82
+
83
  st.title("Garment Pattern Design Tool")
84
 
85
  # Select garment type
 
114
  pattern_output = generate_garment_pattern(body_measurements_str, garment_type)
115
 
116
  # Display the result
117
+