dass777 commited on
Commit
d5b263d
·
verified ·
1 Parent(s): 0e96000

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -13
app.py CHANGED
@@ -2,34 +2,56 @@
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
  import os
 
5
 
6
  HF_TOKEN = os.environ["HF_TOKEN"]
7
- client = InferenceClient(model="black-forest-labs/FLUX.1-dev", token=HF_TOKEN)
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  def add_curtains(image, style="classic", color="beige"):
10
  if image is None:
11
- return None
12
- prompt = f"Add {style} {color} curtains to the window in this photo, photorealistic, natural lighting, soft fabric folds, no distortion"
13
  try:
14
- result = client.image_to_image(
 
 
 
 
 
 
15
  image=image,
 
16
  prompt=prompt,
17
- strength=0.75 # 0.0 = оригинал, 1.0 = полностью новое
18
  )
19
  return result
20
  except Exception as e:
21
- return f"❌ Error: {str(e)}"
22
 
23
  demo = gr.Interface(
24
  fn=add_curtains,
25
  inputs=[
26
- gr.Image(type="pil", label="Photo of your window"),
27
- gr.Radio(["classic", "modern", "roman", "austrian"], value="classic", label="Curtain style"),
28
- gr.Textbox(value="beige", label="Color (e.g. white, navy blue, gray)")
29
  ],
30
- outputs=gr.Image(label="Result with curtains"),
31
- title="🪟 Virtual Curtain Try-On",
32
- description="Upload a photo of your window AI will add realistic curtains!"
33
  )
34
 
35
- demo.launch()
 
 
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
  import os
5
+ from PIL import Image, ImageDraw
6
 
7
  HF_TOKEN = os.environ["HF_TOKEN"]
8
+ client = InferenceClient(token=HF_TOKEN)
9
+
10
+ def create_center_mask(image: Image.Image) -> Image.Image:
11
+ """Создаёт маску в центре изображения (пример для окна)"""
12
+ w, h = image.size
13
+ # Пример: маска 60% ширины и 80% высоты по центру
14
+ left = int(w * 0.2)
15
+ top = int(h * 0.1)
16
+ right = int(w * 0.8)
17
+ bottom = int(h * 0.9)
18
+ mask = Image.new("L", (w, h), 0)
19
+ draw = ImageDraw.Draw(mask)
20
+ draw.rectangle([left, top, right, bottom], fill=255)
21
+ return mask
22
 
23
  def add_curtains(image, style="classic", color="beige"):
24
  if image is None:
25
+ return "❌ Загрузите фото окна"
26
+
27
  try:
28
+ # Создаём маску (позже можно заменить на ручной выбор)
29
+ mask = create_center_mask(image)
30
+
31
+ prompt = f"{style} {color} curtains on the window, photorealistic, natural lighting, soft fabric"
32
+
33
+ # Вызываем inpainting
34
+ result = client.inpainting(
35
  image=image,
36
+ mask_image=mask,
37
  prompt=prompt,
38
+ model="diffusers/stable-diffusion-xl-1.0-inpainting-0.1"
39
  )
40
  return result
41
  except Exception as e:
42
+ return f"❌ Ошибка: {str(e)}"
43
 
44
  demo = gr.Interface(
45
  fn=add_curtains,
46
  inputs=[
47
+ gr.Image(type="pil", label="Фото вашего окна"),
48
+ gr.Radio(["classic", "modern", "roman"], value="classic", label="Стиль штор"),
49
+ gr.Textbox(value="beige", label="Цвет (например: white, navy blue)")
50
  ],
51
+ outputs=gr.Image(label="Результат со шторами"),
52
+ title="🪟 Виртуальная примерка штор",
53
+ description="Загрузите фото окнаИИ добавит шторы!"
54
  )
55
 
56
+ if __name__ == "__main__":
57
+ demo.launch()