Views
No views yet
# Obtenir votre token gratuit sur : https://huggingface.co/settings/tokens
self.headers = {"Authorization": "Bearer VOTRE_TOKEN_ICI"}
def creer_masque_simple(self, image_path, zone):
"""Crée un masque pour les zones à modifier"""
img = Image.open(image_path)
w, h = img.size
mask = Image.new('L', (w, h), 0)
draw = ImageDraw.Draw(mask)
if zone == "bras":
# Rectangles pour les manches
draw.rectangle([int(w*0.20), int(h*0.45), int(w*0.35), int(h*0.70)], fill=255)
draw.rectangle([int(w*0.50), int(h*0.45), int(w*0.65), int(h*0.70)], fill=255)
elif zone == "jupe":
draw.rectangle([int(w*0.35), int(h*0.68), int(w*0.55), int(h*0.82)], fill=255)
return mask
def modifier_avec_inpainting(self, image_path, mask, prompt):
"""Utilise l'API Hugging Face pour l'inpainting"""
# Préparer les données
with open(image_path, "rb") as f:
image_bytes = f.read()
mask_bytes = io.BytesIO()
mask.save(mask_bytes, format='PNG')
mask_bytes = mask_bytes.getvalue()
# Requête API
payload = {
"inputs": prompt,
}
files = {
"image": image_bytes,
"mask": mask_bytes
}
response = requests.post(
self.api_url_inpaint,
headers=self.headers,
data=payload,
files=files
)
if response.status_code == 200:
return Image.open(io.BytesIO(response.content))
else:
print(f"Erreur API: {response.status_code}")
return None
def appliquer_eclairage_local(self, image_path):
"""Version locale de l'éclairage tamisé (sans API)"""
img = Image.open(image_path)
img_array = np.array(img).astype(float)
h, w = img_array.shape[:2]
# Créer vignettage
center_x, center_y = int(w * 0.45), int(h * 0.50)
Y, X = np.ogrid[:h, :w]
dist = np.sqrt((X - center_x)**2 + (Y - center_y)**2)
max_dist = np.sqrt(center_x**2 + center_y**2)
vignette = 1.0 - (dist / max_dist) * 0.65
vignette = np.clip(vignette, 0.35, 1.0)
for i in range(3):
img_array[:, :, i] *= vignette
img_array *= 0.70
img_array = np.clip(img_array, 0, 255).astype(np.uint8)
return Image.fromarray(img_array)
def process_complete(self, image_path, output_path="resultat.jpg"):
"""Processus complet de modification"""
print("🎨 Début des modifications...\n")
# 1. Éclairage (local, gratuit, instantané)
print("1/3 - Éclairage tamisé...")
img = self.appliquer_eclairage_local(image_path)
img.save("temp_eclairage.jpg")
# 2. Modifier la jupe (API)
print("2/3 - Raccourcissement jupe...")
mask_jupe = self.creer_masque_simple("temp_eclairage.jpg", "jupe")
img = self.modifier_avec_inpainting(
"temp_eclairage.jpg",
mask_jupe,
"shorter white mini skirt, thighs visible"
)
if img:
img.save("temp_jupe.jpg")
# 3. Découvrir les bras (API)
print("3/3 - Découvrir les bras...")
mask_bras = self.creer_masque_simple("temp_jupe.jpg", "bras")
img_final = self.modifier_avec_inpainting(
"temp_jupe.jpg",
mask_bras,
"sleeveless black top, bare arms visible"
)
if img_final:
img_final.save(output_path, quality=95)
print(f"\n✅ Terminé ! Image sauvegardée : {output_path}")
return img_final
else:
print("\n❌ Erreur lors du traitement")
return None
## 📱 Option Mobile (Gratuite)
**Remini** (iOS/Android)
- Télécharger l'app
- Fonctionnalité "AI Enhance"
- Limité mais gratuit
**Picsart** (iOS/Android)
- Fonction "AI Replace"
- Gratuit avec pub
## 🎯 Ma Recommandation
**Pour votre cas précis, je vous recommande cette approche hybride :**
1. **Éclairage tamisé** → Utilisez Photopea (gratuit, manuel, 5 min)
2. **Modifier vêtements** → Hugging Face Spaces
3. **Regard vers caméra** → ClipDrop Cleanup + Redraw