floatingping commited on
Commit
70dc6b0
·
1 Parent(s): 9bf0aab
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -15,14 +15,16 @@ def image_to_data_uri(image_path):
15
  return f"data:{mime};base64,{data}"
16
 
17
 
18
- def edit_images(images, prompt, token: gr.OAuthToken | None = None):
19
  if not token:
20
  raise gr.Error("Please sign in with your Hugging Face account first.")
21
- if not images or len(images) == 0:
22
- raise gr.Error("Please upload at least one image.")
23
  if not prompt or prompt.strip() == "":
24
  raise gr.Error("Please enter a prompt.")
25
 
 
 
 
 
26
  client = InferenceClient(provider=PROVIDER, token=token.token)
27
 
28
  image_urls = [image_to_data_uri(img) for img in images]
@@ -48,12 +50,10 @@ with gr.Blocks(fill_height=True) as demo:
48
 
49
  with gr.Row():
50
  with gr.Column():
51
- input_images = gr.File(
52
- label="Upload Images",
53
- file_count="multiple",
54
- file_types=["image"],
55
- type="filepath",
56
- )
57
  prompt = gr.Textbox(
58
  label="Edit Prompt",
59
  placeholder="Describe how you want the image(s) edited...",
@@ -66,7 +66,7 @@ with gr.Blocks(fill_height=True) as demo:
66
 
67
  submit_btn.click(
68
  fn=edit_images,
69
- inputs=[input_images, prompt],
70
  outputs=[output_image],
71
  )
72
 
 
15
  return f"data:{mime};base64,{data}"
16
 
17
 
18
+ def edit_images(img1, img2, img3, prompt, token: gr.OAuthToken | None = None):
19
  if not token:
20
  raise gr.Error("Please sign in with your Hugging Face account first.")
 
 
21
  if not prompt or prompt.strip() == "":
22
  raise gr.Error("Please enter a prompt.")
23
 
24
+ images = [img for img in [img1, img2, img3] if img is not None]
25
+ if len(images) == 0:
26
+ raise gr.Error("Please upload at least one image.")
27
+
28
  client = InferenceClient(provider=PROVIDER, token=token.token)
29
 
30
  image_urls = [image_to_data_uri(img) for img in images]
 
50
 
51
  with gr.Row():
52
  with gr.Column():
53
+ with gr.Row():
54
+ img1 = gr.Image(label="Image 1", type="filepath")
55
+ img2 = gr.Image(label="Image 2 (optional)", type="filepath")
56
+ img3 = gr.Image(label="Image 3 (optional)", type="filepath")
 
 
57
  prompt = gr.Textbox(
58
  label="Edit Prompt",
59
  placeholder="Describe how you want the image(s) edited...",
 
66
 
67
  submit_btn.click(
68
  fn=edit_images,
69
+ inputs=[img1, img2, img3, prompt],
70
  outputs=[output_image],
71
  )
72