Spaces:
Sleeping
Sleeping
Commit
Β·
d603030
1
Parent(s):
ca6b00e
update
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import fal_client
|
|
| 4 |
import os
|
| 5 |
import base64
|
| 6 |
import io
|
|
|
|
| 7 |
from PIL import Image
|
| 8 |
from google import genai
|
| 9 |
from google.genai.types import GenerateContentConfig, ImageConfig, Part
|
|
@@ -11,7 +12,7 @@ from google.genai.types import GenerateContentConfig, ImageConfig, Part
|
|
| 11 |
RUNPOD_API_KEY = os.getenv("RUNPOD_API_KEY")
|
| 12 |
FAL_KEY = os.getenv("FAL_KEY")
|
| 13 |
GEMINI_API_KEY = os.getenv("GEMINI_VLM_KEY")
|
| 14 |
-
QWEN_ENDPOINT_ID =
|
| 15 |
|
| 16 |
os.environ["FAL_KEY"] = FAL_KEY if FAL_KEY else ""
|
| 17 |
gemini_client = genai.Client(api_key=GEMINI_API_KEY) if GEMINI_API_KEY else None
|
|
@@ -21,11 +22,7 @@ DEFAULT_PROMPT = "Add furnishings and accessories to this room as an interior de
|
|
| 21 |
def get_closest_ratio(pil_img):
|
| 22 |
w, h = pil_img.size
|
| 23 |
ratio = w / h
|
| 24 |
-
ratios = {
|
| 25 |
-
"9:16": 0.56, "2:3": 0.66, "3:4": 0.75, "4:5": 0.8,
|
| 26 |
-
"1:1": 1.0, "5:4": 1.25, "4:3": 1.33, "3:2": 1.5,
|
| 27 |
-
"16:9": 1.77, "21:9": 2.33
|
| 28 |
-
}
|
| 29 |
return min(ratios, key=lambda x: abs(ratios[x] - ratio))
|
| 30 |
|
| 31 |
def b64_to_pil(b64_str):
|
|
@@ -80,20 +77,23 @@ def run_gemini(image_bytes, prompt, ratio_str):
|
|
| 80 |
def compare_all(image_file, image_url, prompt):
|
| 81 |
raw_bytes, raw_b64, web_url = get_image_inputs(image_file, image_url)
|
| 82 |
if not raw_bytes:
|
| 83 |
-
yield None, None, None, None
|
| 84 |
return
|
| 85 |
|
| 86 |
og_pil = bytes_to_pil(raw_bytes)
|
| 87 |
ratio_str = get_closest_ratio(og_pil)
|
| 88 |
-
|
| 89 |
|
| 90 |
-
yield og_pil,
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
yield og_pil,
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
with gr.Blocks() as demo:
|
| 99 |
gr.HTML("<h2 style='text-align: center; margin: 10px 0;'>ποΈ Interior Design Model Arena</h2>")
|
|
@@ -115,20 +115,31 @@ with gr.Blocks() as demo:
|
|
| 115 |
with gr.Row():
|
| 116 |
with gr.Column():
|
| 117 |
gr.HTML("<center><b>QWEN-EDIT</b><br><small>$0.004 - $0.008</small></center>")
|
|
|
|
| 118 |
out_qwen = gr.Image(show_label=False, type="pil", height=350)
|
| 119 |
|
| 120 |
with gr.Column():
|
| 121 |
gr.HTML("<center><b>FLUX-2 EDIT</b><br><small>$0.03</small></center>")
|
|
|
|
| 122 |
out_fal = gr.Image(show_label=False, type="pil", height=350)
|
| 123 |
|
| 124 |
with gr.Column():
|
| 125 |
gr.HTML("<center><b>GEMINI 2.5 FLASH</b><br><small>$0.039</small></center>")
|
|
|
|
| 126 |
out_gemini = gr.Image(show_label=False, type="pil", height=350)
|
| 127 |
|
| 128 |
-
run_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
if __name__ == "__main__":
|
| 131 |
demo.launch(
|
| 132 |
server_name="0.0.0.0", server_port=7860, theme=gr.themes.Soft(),
|
| 133 |
-
css="
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
)
|
|
|
|
| 4 |
import os
|
| 5 |
import base64
|
| 6 |
import io
|
| 7 |
+
import time
|
| 8 |
from PIL import Image
|
| 9 |
from google import genai
|
| 10 |
from google.genai.types import GenerateContentConfig, ImageConfig, Part
|
|
|
|
| 12 |
RUNPOD_API_KEY = os.getenv("RUNPOD_API_KEY")
|
| 13 |
FAL_KEY = os.getenv("FAL_KEY")
|
| 14 |
GEMINI_API_KEY = os.getenv("GEMINI_VLM_KEY")
|
| 15 |
+
QWEN_ENDPOINT_ID = "jzpm1xin5cprff"
|
| 16 |
|
| 17 |
os.environ["FAL_KEY"] = FAL_KEY if FAL_KEY else ""
|
| 18 |
gemini_client = genai.Client(api_key=GEMINI_API_KEY) if GEMINI_API_KEY else None
|
|
|
|
| 22 |
def get_closest_ratio(pil_img):
|
| 23 |
w, h = pil_img.size
|
| 24 |
ratio = w / h
|
| 25 |
+
ratios = {"9:16": 0.56, "2:3": 0.66, "3:4": 0.75, "4:5": 0.8, "1:1": 1.0, "5:4": 1.25, "4:3": 1.33, "3:2": 1.5, "16:9": 1.77, "21:9": 2.33}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
return min(ratios, key=lambda x: abs(ratios[x] - ratio))
|
| 27 |
|
| 28 |
def b64_to_pil(b64_str):
|
|
|
|
| 77 |
def compare_all(image_file, image_url, prompt):
|
| 78 |
raw_bytes, raw_b64, web_url = get_image_inputs(image_file, image_url)
|
| 79 |
if not raw_bytes:
|
| 80 |
+
yield None, None, None, None, "", "", ""
|
| 81 |
return
|
| 82 |
|
| 83 |
og_pil = bytes_to_pil(raw_bytes)
|
| 84 |
ratio_str = get_closest_ratio(og_pil)
|
| 85 |
+
q_img, f_img, g_img = None, None, None
|
| 86 |
|
| 87 |
+
yield og_pil, q_img, f_img, g_img, "β³ Processing (~5s)...", "π Pending...", "π Pending..."
|
| 88 |
+
q_img = run_qwen(raw_b64, prompt)
|
| 89 |
+
|
| 90 |
+
yield og_pil, q_img, f_img, g_img, "β
Complete", "β³ Processing (~12s)...", "π Pending..."
|
| 91 |
+
f_img = run_fal_flux(web_url, prompt)
|
| 92 |
+
|
| 93 |
+
yield og_pil, q_img, f_img, g_img, "β
Complete", "β
Complete", "β³ Processing (~15s)..."
|
| 94 |
+
g_img = run_gemini(raw_bytes, prompt, ratio_str)
|
| 95 |
+
|
| 96 |
+
yield og_pil, q_img, f_img, g_img, "β
Complete", "β
Complete", "β
Complete"
|
| 97 |
|
| 98 |
with gr.Blocks() as demo:
|
| 99 |
gr.HTML("<h2 style='text-align: center; margin: 10px 0;'>ποΈ Interior Design Model Arena</h2>")
|
|
|
|
| 115 |
with gr.Row():
|
| 116 |
with gr.Column():
|
| 117 |
gr.HTML("<center><b>QWEN-EDIT</b><br><small>$0.004 - $0.008</small></center>")
|
| 118 |
+
stat_q = gr.Markdown("π Waiting...", elem_classes="status-msg")
|
| 119 |
out_qwen = gr.Image(show_label=False, type="pil", height=350)
|
| 120 |
|
| 121 |
with gr.Column():
|
| 122 |
gr.HTML("<center><b>FLUX-2 EDIT</b><br><small>$0.03</small></center>")
|
| 123 |
+
stat_f = gr.Markdown("π Waiting...", elem_classes="status-msg")
|
| 124 |
out_fal = gr.Image(show_label=False, type="pil", height=350)
|
| 125 |
|
| 126 |
with gr.Column():
|
| 127 |
gr.HTML("<center><b>GEMINI 2.5 FLASH</b><br><small>$0.039</small></center>")
|
| 128 |
+
stat_g = gr.Markdown("π Waiting...", elem_classes="status-msg")
|
| 129 |
out_gemini = gr.Image(show_label=False, type="pil", height=350)
|
| 130 |
|
| 131 |
+
run_btn.click(
|
| 132 |
+
fn=compare_all,
|
| 133 |
+
inputs=[input_file, input_url, input_prompt],
|
| 134 |
+
outputs=[out_og, out_qwen, out_fal, out_gemini, stat_q, stat_f, stat_g]
|
| 135 |
+
)
|
| 136 |
|
| 137 |
if __name__ == "__main__":
|
| 138 |
demo.launch(
|
| 139 |
server_name="0.0.0.0", server_port=7860, theme=gr.themes.Soft(),
|
| 140 |
+
css="""
|
| 141 |
+
.gradio-container {max-width: 98% !important}
|
| 142 |
+
img {object-fit: contain !important;}
|
| 143 |
+
.status-msg {text-align: center; margin-top: -10px; font-size: 0.85em; color: #666;}
|
| 144 |
+
"""
|
| 145 |
)
|