Nightfury16 commited on
Commit
f2cdd8b
·
1 Parent(s): 345e4db
Files changed (1) hide show
  1. app.py +29 -30
app.py CHANGED
@@ -28,20 +28,17 @@ def bytes_to_pil(img_bytes):
28
  return Image.open(io.BytesIO(img_bytes))
29
 
30
  def get_image_inputs(image_file, image_url):
31
- """Returns (raw_bytes, raw_b64, fal_url)"""
32
  if image_file:
33
  with open(image_file, "rb") as f:
34
  raw_bytes = f.read()
35
  raw_b64 = base64.b64encode(raw_bytes).decode('utf-8')
36
  fal_url = fal_client.upload_file(image_file)
37
  return raw_bytes, raw_b64, fal_url
38
-
39
  elif image_url:
40
  resp = requests.get(image_url)
41
  raw_bytes = resp.content
42
  raw_b64 = base64.b64encode(raw_bytes).decode('utf-8')
43
  return raw_bytes, raw_b64, image_url
44
-
45
  return None, None, None
46
 
47
  def run_qwen(raw_b64, prompt):
@@ -79,68 +76,70 @@ def run_gemini(image_bytes, prompt):
79
  if not gemini_client: return None
80
  try:
81
  response = gemini_client.models.generate_content(
82
- model="gemini-2.5-flash-image",
83
- contents=[
84
- Part.from_bytes(data=image_bytes, mime_type="image/jpeg"),
85
- prompt
86
- ],
87
  config=GenerateContentConfig(
88
  response_modalities=["IMAGE"],
89
- image_config=ImageConfig(aspect_ratio="4:3"),
90
  candidate_count=1,
91
  ),
92
  )
93
  for part in response.candidates[0].content.parts:
94
  if part.inline_data:
95
  return bytes_to_pil(part.inline_data.data)
96
- except Exception as e:
97
- print(f"Gemini Error: {e}")
98
  return None
99
 
100
  def compare_all(image_file, image_url, prompt):
101
  raw_bytes, raw_b64, web_url = get_image_inputs(image_file, image_url)
102
  if not raw_bytes:
103
- yield None, None, None
104
  return
105
 
 
106
  qwen_img, flux_img, gemini_img = None, None, None
107
-
 
 
108
  qwen_img = run_qwen(raw_b64, prompt)
109
- yield qwen_img, flux_img, gemini_img
110
 
111
  flux_img = run_fal_flux(web_url, prompt)
112
- yield qwen_img, flux_img, gemini_img
113
 
114
  gemini_img = run_gemini(raw_bytes, prompt)
115
- yield qwen_img, flux_img, gemini_img
116
 
117
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
118
  gr.Markdown("# 🛋️ Interior Design Model Arena")
119
 
120
  with gr.Row():
 
 
121
  with gr.Column(scale=1):
122
- input_file = gr.Image(label="Upload Image", type="filepath")
123
- input_url = gr.Textbox(label="OR: Image URL")
124
- input_prompt = gr.Textbox(label="Prompt", value=DEFAULT_PROMPT, lines=4)
125
- run_btn = gr.Button("Generate Comparison", variant="primary")
126
 
127
  with gr.Row():
128
  with gr.Column():
129
- gr.Markdown("### Qwen-Edit\n**$0.004 - $0.008 /req**")
130
- out_qwen = gr.Image(label="Qwen Result", type="pil")
131
-
132
  with gr.Column():
133
- gr.Markdown("### Flux-2 Edit\n**$0.03 /req**")
134
- out_fal = gr.Image(label="Flux Result", type="pil")
135
-
 
 
136
  with gr.Column():
137
- gr.Markdown("### Gemini 2.5 Flash\n**$0.039 /req**")
138
- out_gemini = gr.Image(label="Gemini Result", type="pil")
139
 
140
  run_btn.click(
141
  fn=compare_all,
142
  inputs=[input_file, input_url, input_prompt],
143
- outputs=[out_qwen, out_fal, out_gemini]
144
  )
145
 
146
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
28
  return Image.open(io.BytesIO(img_bytes))
29
 
30
  def get_image_inputs(image_file, image_url):
 
31
  if image_file:
32
  with open(image_file, "rb") as f:
33
  raw_bytes = f.read()
34
  raw_b64 = base64.b64encode(raw_bytes).decode('utf-8')
35
  fal_url = fal_client.upload_file(image_file)
36
  return raw_bytes, raw_b64, fal_url
 
37
  elif image_url:
38
  resp = requests.get(image_url)
39
  raw_bytes = resp.content
40
  raw_b64 = base64.b64encode(raw_bytes).decode('utf-8')
41
  return raw_bytes, raw_b64, image_url
 
42
  return None, None, None
43
 
44
  def run_qwen(raw_b64, prompt):
 
76
  if not gemini_client: return None
77
  try:
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)
95
  if not raw_bytes:
96
+ yield None, None, None, None
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,
140
  inputs=[input_file, input_url, input_prompt],
141
+ outputs=[out_og, out_qwen, out_fal, out_gemini]
142
  )
143
 
144
+ if __name__ == "__main__":
145
+ demo.launch(server_name="0.0.0.0", server_port=7860)