Spaces:
Sleeping
Sleeping
wracell
commited on
Commit
Β·
d26f75e
1
Parent(s):
ab12f4d
modifications
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ from torchvision import transforms, models
|
|
| 6 |
from segment_anything import sam_model_registry, SamPredictor
|
| 7 |
from io import BytesIO
|
| 8 |
import base64
|
| 9 |
-
import requests
|
| 10 |
from google.generativeai import configure, GenerativeModel
|
| 11 |
|
| 12 |
# Configure Gemini API
|
|
@@ -51,14 +50,17 @@ def analyze_garment(image, style_pref=None, feedback=None, generate_variations=F
|
|
| 51 |
|
| 52 |
style_input = f"\nStyle preference: {style_pref}" if style_pref else ""
|
| 53 |
feedback_input = f"\nUser feedback: {feedback}" if feedback else ""
|
| 54 |
-
variation_input = "\nGenerate 3 variations
|
| 55 |
|
| 56 |
prompt = {
|
| 57 |
"parts": [
|
| 58 |
{
|
| 59 |
"text": (
|
| 60 |
-
"
|
| 61 |
-
"
|
|
|
|
|
|
|
|
|
|
| 62 |
style_input + feedback_input + variation_input
|
| 63 |
)
|
| 64 |
},
|
|
@@ -94,6 +96,8 @@ if uploaded_file:
|
|
| 94 |
st.session_state.processed_image = None
|
| 95 |
if "segmented_image" not in st.session_state:
|
| 96 |
st.session_state.segmented_image = None
|
|
|
|
|
|
|
| 97 |
|
| 98 |
if st.button("βοΈ Preprocess Image"):
|
| 99 |
st.session_state.processed_image = preprocess_image(image)
|
|
@@ -107,12 +111,11 @@ if uploaded_file:
|
|
| 107 |
# π§βπ€βπ§ Human-AI Interaction
|
| 108 |
st.markdown("### π§ Customize Your Style & Get AI Suggestions")
|
| 109 |
style_pref = st.text_input("π Describe your style preference (e.g., elegant, streetwear, minimalist)")
|
| 110 |
-
feedback = st.text_input("π£οΈ Provide feedback to AI (e.g., Make it more vibrant, Use denim)")
|
| 111 |
-
|
| 112 |
generate_variations = st.checkbox("π¨ Generate design variations")
|
| 113 |
|
| 114 |
if st.button("π€ Analyze & Collaborate with AI"):
|
| 115 |
-
result = analyze_garment(image, style_pref
|
|
|
|
| 116 |
st.success(result)
|
| 117 |
|
| 118 |
# Fabric suggestion extraction (Optional basic parsing)
|
|
@@ -120,4 +123,13 @@ if uploaded_file:
|
|
| 120 |
for line in result.splitlines():
|
| 121 |
if "fabric" in line.lower() or "material" in line.lower():
|
| 122 |
st.info(line)
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
from segment_anything import sam_model_registry, SamPredictor
|
| 7 |
from io import BytesIO
|
| 8 |
import base64
|
|
|
|
| 9 |
from google.generativeai import configure, GenerativeModel
|
| 10 |
|
| 11 |
# Configure Gemini API
|
|
|
|
| 50 |
|
| 51 |
style_input = f"\nStyle preference: {style_pref}" if style_pref else ""
|
| 52 |
feedback_input = f"\nUser feedback: {feedback}" if feedback else ""
|
| 53 |
+
variation_input = "\nGenerate 3 creative variations based on this mixed or hybrid style." if generate_variations else ""
|
| 54 |
|
| 55 |
prompt = {
|
| 56 |
"parts": [
|
| 57 |
{
|
| 58 |
"text": (
|
| 59 |
+
"You are a professional fashion consultant. "
|
| 60 |
+
"Analyze the uploaded garment image and describe its style, fabric, and design elements. "
|
| 61 |
+
"Then, suggest complementary pieces and occasions to wear it. "
|
| 62 |
+
"The user might provide unique or combined style preferences such as 'elegant streetwear' or 'casual luxury'. "
|
| 63 |
+
"In such cases, blend both styles and explain how to balance or merge them." +
|
| 64 |
style_input + feedback_input + variation_input
|
| 65 |
)
|
| 66 |
},
|
|
|
|
| 96 |
st.session_state.processed_image = None
|
| 97 |
if "segmented_image" not in st.session_state:
|
| 98 |
st.session_state.segmented_image = None
|
| 99 |
+
if "last_analysis_result" not in st.session_state:
|
| 100 |
+
st.session_state.last_analysis_result = None
|
| 101 |
|
| 102 |
if st.button("βοΈ Preprocess Image"):
|
| 103 |
st.session_state.processed_image = preprocess_image(image)
|
|
|
|
| 111 |
# π§βπ€βπ§ Human-AI Interaction
|
| 112 |
st.markdown("### π§ Customize Your Style & Get AI Suggestions")
|
| 113 |
style_pref = st.text_input("π Describe your style preference (e.g., elegant, streetwear, minimalist)")
|
|
|
|
|
|
|
| 114 |
generate_variations = st.checkbox("π¨ Generate design variations")
|
| 115 |
|
| 116 |
if st.button("π€ Analyze & Collaborate with AI"):
|
| 117 |
+
result = analyze_garment(image, style_pref)
|
| 118 |
+
st.session_state.last_analysis_result = result
|
| 119 |
st.success(result)
|
| 120 |
|
| 121 |
# Fabric suggestion extraction (Optional basic parsing)
|
|
|
|
| 123 |
for line in result.splitlines():
|
| 124 |
if "fabric" in line.lower() or "material" in line.lower():
|
| 125 |
st.info(line)
|
| 126 |
+
|
| 127 |
+
# Feedback AFTER analysis
|
| 128 |
+
if st.session_state.last_analysis_result:
|
| 129 |
+
st.markdown("### π£οΈ Give Feedback to Improve AI Suggestions")
|
| 130 |
+
feedback = st.text_input("What would you like to adjust or improve?", key="feedback_input")
|
| 131 |
+
|
| 132 |
+
if st.button("π Refine Based on Feedback"):
|
| 133 |
+
updated_result = analyze_garment(image, style_pref, feedback, generate_variations)
|
| 134 |
+
st.session_state.last_analysis_result = updated_result
|
| 135 |
+
st.success(updated_result)
|