Spaces:
Running
Running
Commit
·
f6475e3
1
Parent(s):
c8d72c8
update
Browse files
app.py
CHANGED
|
@@ -4,14 +4,24 @@ import fal_client
|
|
| 4 |
import os
|
| 5 |
import json
|
| 6 |
import time
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
RUNPOD_API_KEY = os.getenv("RUNPOD_API_KEY")
|
| 9 |
FAL_KEY = os.getenv("FAL_KEY")
|
| 10 |
|
|
|
|
|
|
|
| 11 |
os.environ["FAL_KEY"] = FAL_KEY if FAL_KEY else ""
|
| 12 |
|
| 13 |
DEFAULT_PROMPT = "Add furnishings and accessories to this room as an interior designer would do for a real estate staging. The generated image shall have the exact same dimensions as the original image and architectural details. Respect doorways and windows and make sure they are consistent with the source image and not blocked by furniture. Use cute accessories and with appropriate wall space, add smart simple graphic paintings. Use neutral colors with light colored accents to match the colors of the room. Give the area an attractive glow."
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def run_banana(image_url, prompt):
|
| 16 |
url = "https://api.runpod.ai/v2/nano-banana-edit/runsync"
|
| 17 |
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {RUNPOD_API_KEY}"}
|
|
@@ -23,31 +33,36 @@ def run_banana(image_url, prompt):
|
|
| 23 |
}
|
| 24 |
}
|
| 25 |
try:
|
| 26 |
-
response = requests.post(url, headers=headers, json=payload, timeout=
|
| 27 |
return response.json()["output"][0]
|
| 28 |
except Exception as e:
|
| 29 |
-
return
|
| 30 |
|
| 31 |
def run_qwen(image_url, prompt):
|
| 32 |
-
|
|
|
|
| 33 |
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {RUNPOD_API_KEY}"}
|
| 34 |
-
|
| 35 |
-
"input": {
|
| 36 |
-
"enable_base64_output": False,
|
| 37 |
-
"enable_sync_mode": False,
|
| 38 |
-
"images": [image_url],
|
| 39 |
-
"output_format": "jpeg",
|
| 40 |
-
"prompt": prompt,
|
| 41 |
-
"seed": -1,
|
| 42 |
-
"size": "1536*1080"
|
| 43 |
-
}
|
| 44 |
-
}
|
| 45 |
try:
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
res_data = response.json()
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
except Exception as e:
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
def run_fal_flux(image_url, prompt):
|
| 53 |
try:
|
|
@@ -61,9 +76,11 @@ def run_fal_flux(image_url, prompt):
|
|
| 61 |
result = handler.get()
|
| 62 |
return result['images'][0]['url']
|
| 63 |
except Exception as e:
|
| 64 |
-
return
|
| 65 |
|
| 66 |
def compare_models(image_url, prompt):
|
|
|
|
|
|
|
| 67 |
res_banana = run_banana(image_url, prompt)
|
| 68 |
res_qwen = run_qwen(image_url, prompt)
|
| 69 |
res_fal = run_fal_flux(image_url, prompt)
|
|
@@ -71,7 +88,7 @@ def compare_models(image_url, prompt):
|
|
| 71 |
|
| 72 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 73 |
gr.Markdown("# 🛋️ Interior Design Model Arena")
|
| 74 |
-
gr.Markdown("Compare
|
| 75 |
|
| 76 |
with gr.Row():
|
| 77 |
with gr.Column(scale=1):
|
|
@@ -81,16 +98,19 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 81 |
|
| 82 |
with gr.Row():
|
| 83 |
with gr.Column():
|
| 84 |
-
gr.Markdown("###
|
| 85 |
-
|
|
|
|
| 86 |
|
| 87 |
with gr.Column():
|
| 88 |
-
gr.Markdown("###
|
| 89 |
-
|
| 90 |
-
|
|
|
|
| 91 |
with gr.Column():
|
| 92 |
-
gr.Markdown("###
|
| 93 |
-
|
|
|
|
| 94 |
|
| 95 |
run_btn.click(
|
| 96 |
fn=compare_models,
|
|
@@ -98,4 +118,5 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 98 |
outputs=[out_banana, out_qwen, out_fal]
|
| 99 |
)
|
| 100 |
|
| 101 |
-
|
|
|
|
|
|
| 4 |
import os
|
| 5 |
import json
|
| 6 |
import time
|
| 7 |
+
import base64
|
| 8 |
+
import io
|
| 9 |
+
from PIL import Image
|
| 10 |
|
| 11 |
RUNPOD_API_KEY = os.getenv("RUNPOD_API_KEY")
|
| 12 |
FAL_KEY = os.getenv("FAL_KEY")
|
| 13 |
|
| 14 |
+
QWEN_ENDPOINT_ID = os.environ["ENDPOINTID"]
|
| 15 |
+
|
| 16 |
os.environ["FAL_KEY"] = FAL_KEY if FAL_KEY else ""
|
| 17 |
|
| 18 |
DEFAULT_PROMPT = "Add furnishings and accessories to this room as an interior designer would do for a real estate staging. The generated image shall have the exact same dimensions as the original image and architectural details. Respect doorways and windows and make sure they are consistent with the source image and not blocked by furniture. Use cute accessories and with appropriate wall space, add smart simple graphic paintings. Use neutral colors with light colored accents to match the colors of the room. Give the area an attractive glow."
|
| 19 |
|
| 20 |
+
def get_as_base64(url):
|
| 21 |
+
"""Helper to convert image URL to base64 for the Qwen endpoint"""
|
| 22 |
+
response = requests.get(url)
|
| 23 |
+
return base64.b64encode(response.content).decode('utf-8')
|
| 24 |
+
|
| 25 |
def run_banana(image_url, prompt):
|
| 26 |
url = "https://api.runpod.ai/v2/nano-banana-edit/runsync"
|
| 27 |
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {RUNPOD_API_KEY}"}
|
|
|
|
| 33 |
}
|
| 34 |
}
|
| 35 |
try:
|
| 36 |
+
response = requests.post(url, headers=headers, json=payload, timeout=90)
|
| 37 |
return response.json()["output"][0]
|
| 38 |
except Exception as e:
|
| 39 |
+
return None
|
| 40 |
|
| 41 |
def run_qwen(image_url, prompt):
|
| 42 |
+
"""Updated to use endpoint jzpm1xin5cprff with base64 logic"""
|
| 43 |
+
url = f"https://api.runpod.ai/v2/{QWEN_ENDPOINT_ID}/runsync"
|
| 44 |
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {RUNPOD_API_KEY}"}
|
| 45 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
try:
|
| 47 |
+
img_b64 = get_as_base64(image_url)
|
| 48 |
+
payload = {
|
| 49 |
+
"input": {
|
| 50 |
+
"image": img_b64,
|
| 51 |
+
"prompt": prompt,
|
| 52 |
+
"seed": 42,
|
| 53 |
+
"use_lightning": True,
|
| 54 |
+
"true_guidance_scale": 2.5,
|
| 55 |
+
"num_inference_steps": 4
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
response = requests.post(url, headers=headers, json=payload, timeout=90)
|
| 59 |
res_data = response.json()
|
| 60 |
+
|
| 61 |
+
img_data = res_data["output"]["images"][0]
|
| 62 |
+
return f"data:image/png;base64,{img_data}"
|
| 63 |
except Exception as e:
|
| 64 |
+
print(f"Qwen Error: {e}")
|
| 65 |
+
return None
|
| 66 |
|
| 67 |
def run_fal_flux(image_url, prompt):
|
| 68 |
try:
|
|
|
|
| 76 |
result = handler.get()
|
| 77 |
return result['images'][0]['url']
|
| 78 |
except Exception as e:
|
| 79 |
+
return None
|
| 80 |
|
| 81 |
def compare_models(image_url, prompt):
|
| 82 |
+
if not image_url:
|
| 83 |
+
return None, None, None
|
| 84 |
res_banana = run_banana(image_url, prompt)
|
| 85 |
res_qwen = run_qwen(image_url, prompt)
|
| 86 |
res_fal = run_fal_flux(image_url, prompt)
|
|
|
|
| 88 |
|
| 89 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 90 |
gr.Markdown("# 🛋️ Interior Design Model Arena")
|
| 91 |
+
gr.Markdown("Compare specialized staging models side-by-side.")
|
| 92 |
|
| 93 |
with gr.Row():
|
| 94 |
with gr.Column(scale=1):
|
|
|
|
| 98 |
|
| 99 |
with gr.Row():
|
| 100 |
with gr.Column():
|
| 101 |
+
gr.Markdown("### Qwen-Edit (New)")
|
| 102 |
+
gr.Markdown("**Price: $0.004 - $0.008 /req**")
|
| 103 |
+
out_qwen = gr.Image(label="Qwen Result", interactive=False)
|
| 104 |
|
| 105 |
with gr.Column():
|
| 106 |
+
gr.Markdown("### Flux-2 Edit")
|
| 107 |
+
gr.Markdown("**Price: $0.024 /req**")
|
| 108 |
+
out_fal = gr.Image(label="Flux Result", interactive=False)
|
| 109 |
+
|
| 110 |
with gr.Column():
|
| 111 |
+
gr.Markdown("### Nano-Banana")
|
| 112 |
+
gr.Markdown("**Price: $0.039 /req**")
|
| 113 |
+
out_banana = gr.Image(label="Banana Result", interactive=False)
|
| 114 |
|
| 115 |
run_btn.click(
|
| 116 |
fn=compare_models,
|
|
|
|
| 118 |
outputs=[out_banana, out_qwen, out_fal]
|
| 119 |
)
|
| 120 |
|
| 121 |
+
if __name__ == "__main__":
|
| 122 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|