Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from datasets import load_dataset
|
| 4 |
+
|
| 5 |
+
# Load dataset and models
|
| 6 |
+
dataset = load_dataset("AntZet/home_decoration_objects_images")
|
| 7 |
+
style_clf = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
| 8 |
+
advice_gen = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 9 |
+
|
| 10 |
+
def get_recommendation(style_input):
|
| 11 |
+
# 1. Find matching styles
|
| 12 |
+
style_examples = [d for d in dataset['train'] if d['style'].lower() == style_input.lower()]
|
| 13 |
+
|
| 14 |
+
if not style_examples:
|
| 15 |
+
return "Style not found. Try: Industrial, Scandinavian, etc."
|
| 16 |
+
|
| 17 |
+
# 2. Get common objects
|
| 18 |
+
objects = [obj for ex in style_examples for obj in ex['objects']]
|
| 19 |
+
top_objects = sorted(set(objects), key=lambda x: -objects.count(x))[:3]
|
| 20 |
+
|
| 21 |
+
# 3. Generate advice
|
| 22 |
+
prompt = f"""As an Airbnb host, how to decorate in {style_input} style?
|
| 23 |
+
Key objects: {top_objects}
|
| 24 |
+
Provide:
|
| 25 |
+
- 3 essential elements
|
| 26 |
+
- 2 budget tips
|
| 27 |
+
- Colors to use"""
|
| 28 |
+
|
| 29 |
+
advice = advice_gen(prompt, max_length=300)[0]['generated_text']
|
| 30 |
+
|
| 31 |
+
# 4. Show example images
|
| 32 |
+
example_images = [ex['image'] for ex in style_examples[:3]]
|
| 33 |
+
|
| 34 |
+
return advice, example_images
|
| 35 |
+
|
| 36 |
+
# Simple UI
|
| 37 |
+
with gr.Blocks() as demo:
|
| 38 |
+
gr.Markdown("## 🏡 Airbnb Style Advisor")
|
| 39 |
+
style_input = gr.Textbox(label="Enter style (e.g. Industrial)")
|
| 40 |
+
submit_btn = gr.Button("Get Advice")
|
| 41 |
+
|
| 42 |
+
with gr.Row():
|
| 43 |
+
advice_output = gr.Textbox(label="Recommendations")
|
| 44 |
+
gallery = gr.Gallery(label="Style Examples")
|
| 45 |
+
|
| 46 |
+
submit_btn.click(
|
| 47 |
+
fn=get_recommendation,
|
| 48 |
+
inputs=style_input,
|
| 49 |
+
outputs=[advice_output, gallery]
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
demo.launch()
|