Spaces:
Sleeping
Sleeping
File size: 3,353 Bytes
2835313 f7140fe 2835313 f7140fe 2835313 f7140fe 2835313 f7140fe 2835313 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
import gradio as gr
import numpy as np
from PIL import Image
import io
from huggingface_hub import InferenceClient
# Initialize client
client = InferenceClient()
def segment_and_edit(image, prompt):
"""
Fast interior design editor using Hugging Face Inference API
"""
try:
# Convert PIL to bytes
img_byte_arr = io.BytesIO()
image.save(img_byte_arr, format='PNG')
img_byte_arr = img_byte_arr.getvalue()
# Use a free, public model for image-to-image
edited_image = client.image_to_image(
image=img_byte_arr,
prompt=f"interior design photo, {prompt}, professional photography, high quality, detailed, realistic",
negative_prompt="blurry, distorted, low quality, watermark, text, cartoon, sketch",
model="black-forest-labs/FLUX.1-schnell", # Fast, public model
)
return edited_image
except Exception as e:
# Fallback to text-to-image if image-to-image fails
try:
generated = client.text_to_image(
prompt=f"interior room design, {prompt}, professional photography, 4k, realistic",
model="black-forest-labs/FLUX.1-schnell"
)
return generated
except Exception as e2:
return None, f"Error: {str(e2)}"
def process_room(image, edit_prompt):
"""Main processing function"""
if image is None:
return None, "Please upload an image"
if not edit_prompt.strip():
return None, "Please provide editing instructions"
# Process the image
result = segment_and_edit(image, edit_prompt)
if isinstance(result, tuple):
return result
return result, "✅ Edit complete!"
# Gradio Interface
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("""
# 🏠 AI Interior Designer Assistant
Upload a room photo and describe your desired changes. Uses AI to redesign your space.
**Example prompts:**
- "Change the sofa to mid-century modern, deep blue velvet"
- "Replace with white minimalist furniture and add plants"
- "Make it Scandinavian style with light wood"
""")
with gr.Row():
with gr.Column():
input_image = gr.Image(type="pil", label="Upload Room Photo")
edit_prompt = gr.Textbox(
label="Describe Your Changes",
placeholder="E.g., change the sofa to modern gray fabric and add a floor lamp",
lines=3
)
submit_btn = gr.Button("Transform Room 🎨", variant="primary")
with gr.Column():
output_image = gr.Image(label="Redesigned Room")
status_text = gr.Textbox(label="Status", interactive=False)
# Examples
gr.Examples(
examples=[
["Change to modern minimalist with white furniture", None],
["Replace with bohemian style, add colorful cushions and plants", None],
["Make it industrial loft style with exposed brick aesthetic", None],
],
inputs=[edit_prompt, input_image],
)
submit_btn.click(
fn=process_room,
inputs=[input_image, edit_prompt],
outputs=[output_image, status_text]
)
if __name__ == "__main__":
demo.launch() |