Nightfury16 commited on
Commit
03e1c51
Β·
1 Parent(s): f2cdd8b
Files changed (1) hide show
  1. app.py +33 -50
app.py CHANGED
@@ -44,33 +44,19 @@ def get_image_inputs(image_file, image_url):
44
  def run_qwen(raw_b64, prompt):
45
  url = f"https://api.runpod.ai/v2/{QWEN_ENDPOINT_ID}/runsync"
46
  headers = {"Content-Type": "application/json", "Authorization": f"Bearer {RUNPOD_API_KEY}"}
47
- payload = {
48
- "input": {
49
- "image": raw_b64,
50
- "prompt": prompt,
51
- "seed": 42,
52
- "use_lightning": True,
53
- "true_guidance_scale": 2.5,
54
- "num_inference_steps": 4
55
- }
56
- }
57
  try:
58
  response = requests.post(url, headers=headers, json=payload, timeout=60)
59
  return b64_to_pil(response.json()["output"]["images"][0])
60
- except:
61
- return None
62
 
63
  def run_fal_flux(image_url, prompt):
64
  try:
65
- handler = fal_client.submit(
66
- "fal-ai/flux-2/edit",
67
- arguments={"prompt": prompt, "image_urls": [image_url]}
68
- )
69
  result = handler.get()
70
  resp = requests.get(result['images'][0]['url'])
71
  return bytes_to_pil(resp.content)
72
- except:
73
- return None
74
 
75
  def run_gemini(image_bytes, prompt):
76
  if not gemini_client: return None
@@ -78,17 +64,11 @@ def run_gemini(image_bytes, prompt):
78
  response = gemini_client.models.generate_content(
79
  model="gemini-2.5-flash-image",
80
  contents=[Part.from_bytes(data=image_bytes, mime_type="image/jpeg"), prompt],
81
- config=GenerateContentConfig(
82
- response_modalities=["IMAGE"],
83
- image_config=ImageConfig(aspect_ratio="16:9"),
84
- candidate_count=1,
85
- ),
86
  )
87
  for part in response.candidates[0].content.parts:
88
- if part.inline_data:
89
- return bytes_to_pil(part.inline_data.data)
90
- except:
91
- return None
92
 
93
  def compare_all(image_file, image_url, prompt):
94
  raw_bytes, raw_b64, web_url = get_image_inputs(image_file, image_url)
@@ -97,43 +77,46 @@ def compare_all(image_file, image_url, prompt):
97
  return
98
 
99
  og_pil = bytes_to_pil(raw_bytes)
100
- qwen_img, flux_img, gemini_img = None, None, None
101
 
102
- yield og_pil, qwen_img, flux_img, gemini_img
103
 
104
- qwen_img = run_qwen(raw_b64, prompt)
105
- yield og_pil, qwen_img, flux_img, gemini_img
106
 
107
- flux_img = run_fal_flux(web_url, prompt)
108
- yield og_pil, qwen_img, flux_img, gemini_img
109
 
110
- gemini_img = run_gemini(raw_bytes, prompt)
111
- yield og_pil, qwen_img, flux_img, gemini_img
112
 
113
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
114
  gr.Markdown("# πŸ›‹οΈ Interior Design Model Arena")
115
 
116
- with gr.Row():
117
- with gr.Column(scale=2):
118
- input_prompt = gr.Textbox(label="Prompt", value=DEFAULT_PROMPT, lines=3)
119
  with gr.Column(scale=1):
120
- input_file = gr.Image(label="Upload Source", type="filepath", height=180)
121
- input_url = gr.Textbox(label="Source URL", placeholder="Optional URL...")
122
- run_btn = gr.Button("Compare Models", variant="primary")
 
123
 
 
 
124
  with gr.Row():
125
  with gr.Column():
126
- gr.Markdown("### Original\nInput Image")
127
- out_og = gr.Image(label="Original", type="pil", height=320)
128
  with gr.Column():
129
- gr.Markdown("### Qwen-Edit\n**$0.004 - $0.008**")
130
- out_qwen = gr.Image(label="Qwen", type="pil", height=320)
131
  with gr.Column():
132
- gr.Markdown("### Flux-2 Edit\n**$0.03**")
133
- out_fal = gr.Image(label="Flux", type="pil", height=320)
134
  with gr.Column():
135
- gr.Markdown("### Gemini 2.5 Flash\n**$0.039**")
136
- out_gemini = gr.Image(label="Gemini", type="pil", height=320)
137
 
138
  run_btn.click(
139
  fn=compare_all,
 
44
  def run_qwen(raw_b64, prompt):
45
  url = f"https://api.runpod.ai/v2/{QWEN_ENDPOINT_ID}/runsync"
46
  headers = {"Content-Type": "application/json", "Authorization": f"Bearer {RUNPOD_API_KEY}"}
47
+ payload = {"input": {"image": raw_b64, "prompt": prompt, "seed": 42, "use_lightning": True, "true_guidance_scale": 2.5, "num_inference_steps": 4}}
 
 
 
 
 
 
 
 
 
48
  try:
49
  response = requests.post(url, headers=headers, json=payload, timeout=60)
50
  return b64_to_pil(response.json()["output"]["images"][0])
51
+ except: return None
 
52
 
53
  def run_fal_flux(image_url, prompt):
54
  try:
55
+ handler = fal_client.submit("fal-ai/flux-2/edit", arguments={"prompt": prompt, "image_urls": [image_url]})
 
 
 
56
  result = handler.get()
57
  resp = requests.get(result['images'][0]['url'])
58
  return bytes_to_pil(resp.content)
59
+ except: return None
 
60
 
61
  def run_gemini(image_bytes, prompt):
62
  if not gemini_client: return None
 
64
  response = gemini_client.models.generate_content(
65
  model="gemini-2.5-flash-image",
66
  contents=[Part.from_bytes(data=image_bytes, mime_type="image/jpeg"), prompt],
67
+ config=GenerateContentConfig(response_modalities=["IMAGE"], image_config=ImageConfig(aspect_ratio="16:9"), candidate_count=1),
 
 
 
 
68
  )
69
  for part in response.candidates[0].content.parts:
70
+ if part.inline_data: return bytes_to_pil(part.inline_data.data)
71
+ except: return None
 
 
72
 
73
  def compare_all(image_file, image_url, prompt):
74
  raw_bytes, raw_b64, web_url = get_image_inputs(image_file, image_url)
 
77
  return
78
 
79
  og_pil = bytes_to_pil(raw_bytes)
80
+ q_img, f_img, g_img = None, None, None
81
 
82
+ yield og_pil, q_img, f_img, g_img
83
 
84
+ q_img = run_qwen(raw_b64, prompt)
85
+ yield og_pil, q_img, f_img, g_img
86
 
87
+ f_img = run_fal_flux(web_url, prompt)
88
+ yield og_pil, q_img, f_img, g_img
89
 
90
+ g_img = run_gemini(raw_bytes, prompt)
91
+ yield og_pil, q_img, f_img, g_img
92
 
93
+ with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {max-width: 95% !important}") as demo:
94
  gr.Markdown("# πŸ›‹οΈ Interior Design Model Arena")
95
 
96
+ with gr.Row(variant="panel"):
97
+ with gr.Column(scale=3):
98
+ input_prompt = gr.Textbox(label="Design Instructions", value=DEFAULT_PROMPT, lines=3)
99
  with gr.Column(scale=1):
100
+ input_file = gr.Image(label="Upload (Fixed Width)", type="filepath", height=120)
101
+ with gr.Column(scale=1):
102
+ input_url = gr.Textbox(label="Or Image URL", placeholder="http://...")
103
+ run_btn = gr.Button("πŸš€ GENERATE ALL", variant="primary", size="lg")
104
 
105
+ gr.Separator()
106
+
107
  with gr.Row():
108
  with gr.Column():
109
+ gr.Markdown("#### πŸ–ΌοΈ Original")
110
+ out_og = gr.Image(show_label=False, type="pil", height=400, show_download_button=False)
111
  with gr.Column():
112
+ gr.Markdown("#### ⚑ Qwen-Edit\n($0.006 avg)")
113
+ out_qwen = gr.Image(show_label=False, type="pil", height=400)
114
  with gr.Column():
115
+ gr.Markdown("#### 🎨 Flux-2\n($0.03)")
116
+ out_fal = gr.Image(show_label=False, type="pil", height=400)
117
  with gr.Column():
118
+ gr.Markdown("#### πŸ’Ž Gemini 2.5\n($0.039)")
119
+ out_gemini = gr.Image(show_label=False, type="pil", height=400)
120
 
121
  run_btn.click(
122
  fn=compare_all,