Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,11 +4,8 @@ import os
|
|
| 4 |
from typing import Optional, List
|
| 5 |
from huggingface_hub import whoami
|
| 6 |
|
| 7 |
-
# It is recommended to create this as a Secret on your Hugging Face Space
|
| 8 |
-
# For example: FAL_KEY = "fal_key_..."
|
| 9 |
FAL_KEY = os.getenv("FAL_KEY", "")
|
| 10 |
|
| 11 |
-
# Set the key for the fal_client
|
| 12 |
if FAL_KEY:
|
| 13 |
fal_client.api_key = FAL_KEY
|
| 14 |
|
|
@@ -34,7 +31,9 @@ def run_single_image_logic(prompt: str, image: Optional[str] = None) -> str:
|
|
| 34 |
"""Handles text-to-image or single image-to-image and returns a single URL string."""
|
| 35 |
get_fal_key()
|
| 36 |
if image:
|
|
|
|
| 37 |
image_url = fal_client.upload_file(image)
|
|
|
|
| 38 |
result = fal_client.run(
|
| 39 |
"fal-ai/nano-banana/edit",
|
| 40 |
arguments={"prompt": prompt, "image_url": image_url},
|
|
@@ -47,21 +46,27 @@ def run_single_image_logic(prompt: str, image: Optional[str] = None) -> str:
|
|
| 47 |
|
| 48 |
def run_multi_image_logic(prompt: str, images: List[str]) -> str:
|
| 49 |
"""
|
| 50 |
-
|
| 51 |
"""
|
| 52 |
get_fal_key()
|
| 53 |
if not images:
|
| 54 |
raise gr.Error("Please upload at least one image in the 'Multiple Images' tab.")
|
| 55 |
|
| 56 |
-
|
| 57 |
-
for image_path in images
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
# --- Gradio App UI ---
|
| 67 |
with gr.Blocks(theme=gr.themes.Citrus()) as demo:
|
|
|
|
| 4 |
from typing import Optional, List
|
| 5 |
from huggingface_hub import whoami
|
| 6 |
|
|
|
|
|
|
|
| 7 |
FAL_KEY = os.getenv("FAL_KEY", "")
|
| 8 |
|
|
|
|
| 9 |
if FAL_KEY:
|
| 10 |
fal_client.api_key = FAL_KEY
|
| 11 |
|
|
|
|
| 31 |
"""Handles text-to-image or single image-to-image and returns a single URL string."""
|
| 32 |
get_fal_key()
|
| 33 |
if image:
|
| 34 |
+
print(image)
|
| 35 |
image_url = fal_client.upload_file(image)
|
| 36 |
+
print(image_url)
|
| 37 |
result = fal_client.run(
|
| 38 |
"fal-ai/nano-banana/edit",
|
| 39 |
arguments={"prompt": prompt, "image_url": image_url},
|
|
|
|
| 46 |
|
| 47 |
def run_multi_image_logic(prompt: str, images: List[str]) -> str:
|
| 48 |
"""
|
| 49 |
+
Uploads multiple images
|
| 50 |
"""
|
| 51 |
get_fal_key()
|
| 52 |
if not images:
|
| 53 |
raise gr.Error("Please upload at least one image in the 'Multiple Images' tab.")
|
| 54 |
|
| 55 |
+
# 1. Upload all images and collect their URLs
|
| 56 |
+
image_urls = [fal_client.upload_file(image_path) for image_path in images]
|
| 57 |
+
|
| 58 |
+
# 2. Make a single API call with the list of URLs
|
| 59 |
+
result = fal_client.run(
|
| 60 |
+
"fal-ai/nano-banana/edit",
|
| 61 |
+
arguments={
|
| 62 |
+
"prompt": prompt,
|
| 63 |
+
"image_urls": image_urls,
|
| 64 |
+
"num_images": 1
|
| 65 |
+
},
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
# 3. Return the single resulting image URL
|
| 69 |
+
return result["images"][0]["url"]
|
| 70 |
|
| 71 |
# --- Gradio App UI ---
|
| 72 |
with gr.Blocks(theme=gr.themes.Citrus()) as demo:
|