Spaces:
Paused
Paused
| import gradio as gr | |
| # Define the function to call the Hugging Face Inference API | |
| # We use a popular text-to-image model suitable for interiors | |
| model_id = "stabilityai/stable-diffusion-2-1" | |
| def generate_interior(prompt, negative_prompt): | |
| # Construct the full prompt for interior design | |
| full_prompt = f"professional interior design photography, {prompt}, 8k, highly detailed, realistic lighting" | |
| full_negative = f"blurry, low quality, distorted, ugly, bad anatomy, {negative_prompt}" | |
| try: | |
| # Load the model directly from Hugging Face Inference API | |
| # This runs on HF's servers, not your free CPU space | |
| pipe = gr.load(f"models/{model_id}") | |
| image = pipe(full_prompt, negative_prompt=full_negative) | |
| return image | |
| except Exception as e: | |
| return f"Error: {str(e)}. The API might be busy. Try again." | |
| # Create the Gradio Interface | |
| with gr.Blocks(theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("# 🏠 Home Interior Design Generator") | |
| gr.Markdown("Describe your dream room, and AI will visualize it.") | |
| with gr.Row(): | |
| with gr.Column(): | |
| input_prompt = gr.Textbox( | |
| label="Room Description", | |
| placeholder="e.g., A modern living room with a large sofa, wooden floor, and large windows overlooking a garden", | |
| lines=3 | |
| ) | |
| neg_prompt = gr.Textbox( | |
| label="Negative Prompt (Optional)", | |
| value="dark, cluttered", | |
| lines=1 | |
| ) | |
| gen_btn = gr.Button("Generate Design", variant="primary") | |
| with gr.Column(): | |
| output_image = gr.Image(label="Generated Interior") | |
| # Connect the button to the function | |
| gen_btn.click( | |
| fn=generate_interior, | |
| inputs=[input_prompt, neg_prompt], | |
| outputs=output_image | |
| ) | |
| # Add examples for users | |
| gr.Examples( | |
| examples=[ | |
| ["A cozy scandinavian bedroom with white walls and a knitted blanket", "dark, messy"], | |
| ["A luxury kitchen with marble countertops and gold fixtures", "blurry, low res"], | |
| ["A minimalist home office with a desk and plants", "cluttered, noisy"] | |
| ], | |
| inputs=input_prompt | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |