shaheerawan3 commited on
Commit
f7140fe
·
verified ·
1 Parent(s): 205afcb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -2,11 +2,9 @@ import gradio as gr
2
  import numpy as np
3
  from PIL import Image
4
  import io
5
- import base64
6
- import requests
7
  from huggingface_hub import InferenceClient
8
 
9
- # Initialize clients
10
  client = InferenceClient()
11
 
12
  def segment_and_edit(image, prompt):
@@ -19,20 +17,26 @@ def segment_and_edit(image, prompt):
19
  image.save(img_byte_arr, format='PNG')
20
  img_byte_arr = img_byte_arr.getvalue()
21
 
22
- # Use ControlNet Canny for guided editing (faster than segmentation)
23
- # This maintains room structure while applying edits
24
  edited_image = client.image_to_image(
25
  image=img_byte_arr,
26
- prompt=f"interior design photo, {prompt}, professional photography, 4k, detailed",
27
- negative_prompt="blurry, distorted, low quality, watermark",
28
- model="stabilityai/stable-diffusion-2-1",
29
- strength=0.75, # Balance between original and edit
30
  )
31
 
32
  return edited_image
33
 
34
  except Exception as e:
35
- return None, f"Error: {str(e)}"
 
 
 
 
 
 
 
 
36
 
37
  def process_room(image, edit_prompt):
38
  """Main processing function"""
 
2
  import numpy as np
3
  from PIL import Image
4
  import io
 
 
5
  from huggingface_hub import InferenceClient
6
 
7
+ # Initialize client
8
  client = InferenceClient()
9
 
10
  def segment_and_edit(image, prompt):
 
17
  image.save(img_byte_arr, format='PNG')
18
  img_byte_arr = img_byte_arr.getvalue()
19
 
20
+ # Use a free, public model for image-to-image
 
21
  edited_image = client.image_to_image(
22
  image=img_byte_arr,
23
+ prompt=f"interior design photo, {prompt}, professional photography, high quality, detailed, realistic",
24
+ negative_prompt="blurry, distorted, low quality, watermark, text, cartoon, sketch",
25
+ model="black-forest-labs/FLUX.1-schnell", # Fast, public model
 
26
  )
27
 
28
  return edited_image
29
 
30
  except Exception as e:
31
+ # Fallback to text-to-image if image-to-image fails
32
+ try:
33
+ generated = client.text_to_image(
34
+ prompt=f"interior room design, {prompt}, professional photography, 4k, realistic",
35
+ model="black-forest-labs/FLUX.1-schnell"
36
+ )
37
+ return generated
38
+ except Exception as e2:
39
+ return None, f"Error: {str(e2)}"
40
 
41
  def process_room(image, edit_prompt):
42
  """Main processing function"""