Spaces:
Sleeping
Sleeping
wracell
commited on
Commit
ยท
b86d733
1
Parent(s):
7ef7b02
added instructions and desciptions for the app
Browse files- app.py +29 -4
- requirements.txt +1 -2
app.py
CHANGED
|
@@ -6,7 +6,6 @@ import torch
|
|
| 6 |
import torchvision.transforms as transforms
|
| 7 |
import torchvision.models as models
|
| 8 |
from io import BytesIO
|
| 9 |
-
import open3d as o3d
|
| 10 |
from google.generativeai import configure, GenerativeModel
|
| 11 |
import base64
|
| 12 |
|
|
@@ -83,7 +82,7 @@ def preprocess_image(image):
|
|
| 83 |
edges = cv2.Canny(gray, 100, 200)
|
| 84 |
return Image.fromarray(edges)
|
| 85 |
|
| 86 |
-
# AI garment analysis
|
| 87 |
def analyze_garment(image):
|
| 88 |
# Convert PIL Image to bytes
|
| 89 |
image_bytes = BytesIO()
|
|
@@ -96,7 +95,10 @@ def analyze_garment(image):
|
|
| 96 |
# Prepare request payload in correct Gemini API format
|
| 97 |
prompt = {
|
| 98 |
"parts": [
|
| 99 |
-
{"text": "Analyze the garment in this image, describing its style, fabric, and design elements."
|
|
|
|
|
|
|
|
|
|
| 100 |
{"inline_data": {"mime_type": "image/png", "data": encoded_image}}
|
| 101 |
]
|
| 102 |
}
|
|
@@ -106,12 +108,35 @@ def analyze_garment(image):
|
|
| 106 |
|
| 107 |
return response.text if response else "Analysis failed."
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
# Load segmentation model
|
| 110 |
segmentation_model = load_segmentation_model()
|
| 111 |
|
| 112 |
# Streamlit UI
|
| 113 |
st.title("๐ AI-Enhanced Fashion Design with Gemini 2.0 Flash")
|
| 114 |
-
st.write("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
# File Upload
|
| 117 |
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
|
|
|
|
| 6 |
import torchvision.transforms as transforms
|
| 7 |
import torchvision.models as models
|
| 8 |
from io import BytesIO
|
|
|
|
| 9 |
from google.generativeai import configure, GenerativeModel
|
| 10 |
import base64
|
| 11 |
|
|
|
|
| 82 |
edges = cv2.Canny(gray, 100, 200)
|
| 83 |
return Image.fromarray(edges)
|
| 84 |
|
| 85 |
+
# AI garment analysis & fashion recommendations
|
| 86 |
def analyze_garment(image):
|
| 87 |
# Convert PIL Image to bytes
|
| 88 |
image_bytes = BytesIO()
|
|
|
|
| 95 |
# Prepare request payload in correct Gemini API format
|
| 96 |
prompt = {
|
| 97 |
"parts": [
|
| 98 |
+
{"text": "Analyze the garment in this image, describing its style, fabric, and design elements. "
|
| 99 |
+
"Based on the garment's features, suggest the best occasions to wear it "
|
| 100 |
+
"and recommend complementary fashion pieces (e.g., shoes, accessories, layering options). "
|
| 101 |
+
"Also, provide a seasonal suitability rating."},
|
| 102 |
{"inline_data": {"mime_type": "image/png", "data": encoded_image}}
|
| 103 |
]
|
| 104 |
}
|
|
|
|
| 108 |
|
| 109 |
return response.text if response else "Analysis failed."
|
| 110 |
|
| 111 |
+
|
| 112 |
+
# Call Gemini API
|
| 113 |
+
response = model.generate_content(prompt)
|
| 114 |
+
|
| 115 |
+
return response.text if response else "Analysis failed."
|
| 116 |
+
|
| 117 |
# Load segmentation model
|
| 118 |
segmentation_model = load_segmentation_model()
|
| 119 |
|
| 120 |
# Streamlit UI
|
| 121 |
st.title("๐ AI-Enhanced Fashion Design with Gemini 2.0 Flash")
|
| 122 |
+
st.write("""
|
| 123 |
+
### ๐จ **About This App**
|
| 124 |
+
This AI-powered fashion tool helps you analyze and enhance garment designs using Google's **Gemini 2.0 Flash** and DeepLabV3 segmentation.
|
| 125 |
+
It provides recommendations on **suitable fashion styles** for different occasions based on the uploaded garment.
|
| 126 |
+
|
| 127 |
+
### ๐ **How to Use This App**
|
| 128 |
+
1. **Upload an Image** โ Select a clothing item or a fashion sketch.
|
| 129 |
+
2. **View Preprocessing & Segmentation** โ The app applies edge detection and garment segmentation.
|
| 130 |
+
3. **Analyze Garment** โ Click "Analyze Garment" to get AI-powered fashion insights.
|
| 131 |
+
4. **Get Recommendations** โ The AI suggests suitable **occasions and styling tips** based on the garment.
|
| 132 |
+
|
| 133 |
+
### ๐ **How It Works**
|
| 134 |
+
- **Edge Detection**: Uses OpenCV to highlight contours and details in the garment.
|
| 135 |
+
- **Garment Segmentation**: DeepLabV3 identifies the clothing item and removes the background.
|
| 136 |
+
- **AI Fashion Analysis**: Googleโs Gemini AI analyzes the **style, fabric, and design** of the garment and provides recommendations.
|
| 137 |
+
|
| 138 |
+
โก๏ธ Try it now by uploading an image of your clothing!
|
| 139 |
+
""")
|
| 140 |
|
| 141 |
# File Upload
|
| 142 |
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
|
requirements.txt
CHANGED
|
@@ -4,5 +4,4 @@ opencv-python
|
|
| 4 |
pillow
|
| 5 |
torch
|
| 6 |
torchvision
|
| 7 |
-
google-generativeai
|
| 8 |
-
open3d
|
|
|
|
| 4 |
pillow
|
| 5 |
torch
|
| 6 |
torchvision
|
| 7 |
+
google-generativeai
|
|
|