Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,18 +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 |
-
|
| 12 |
-
if FAL_KEY:
|
| 13 |
-
fal_client.api_key = FAL_KEY
|
| 14 |
-
|
| 15 |
-
def get_fal_key():
|
| 16 |
-
"""Checks for the FAL_KEY and raises a Gradio error if it's not set."""
|
| 17 |
-
if not FAL_KEY:
|
| 18 |
-
raise gr.Error("FAL_KEY is not set. Please add it to your Hugging Face Space secrets.")
|
| 19 |
|
| 20 |
def verify_pro_status(token: Optional[gr.OAuthToken]) -> bool:
|
| 21 |
"""Verifies if the user is a Hugging Face PRO user using their token."""
|
|
@@ -32,7 +22,6 @@ def verify_pro_status(token: Optional[gr.OAuthToken]) -> bool:
|
|
| 32 |
|
| 33 |
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(
|
|
@@ -50,7 +39,6 @@ def run_multi_image_logic(prompt: str, images: List[str]) -> str:
|
|
| 50 |
"""
|
| 51 |
Handles multi-image editing by sending a list of URLs in a single API call.
|
| 52 |
"""
|
| 53 |
-
get_fal_key()
|
| 54 |
if not images:
|
| 55 |
raise gr.Error("Please upload at least one image in the 'Multiple Images' tab.")
|
| 56 |
|
|
@@ -75,7 +63,7 @@ with gr.Blocks(theme=gr.themes.Citrus()) as demo:
|
|
| 75 |
main_interface = gr.Column(visible=False)
|
| 76 |
|
| 77 |
with main_interface:
|
| 78 |
-
gr.Markdown("## Thanks for being a PRO
|
| 79 |
with gr.Row():
|
| 80 |
with gr.Column(scale=1):
|
| 81 |
active_tab_state = gr.State(value="single")
|
|
@@ -96,13 +84,11 @@ with gr.Blocks(theme=gr.themes.Citrus()) as demo:
|
|
| 96 |
)
|
| 97 |
generate_button = gr.Button("Generate", variant="primary")
|
| 98 |
|
| 99 |
-
# RIGHT COLUMN: Outputs
|
| 100 |
with gr.Column(scale=1):
|
| 101 |
output_image = gr.Image(label="Output", interactive=False)
|
| 102 |
use_image_button = gr.Button("♻️ Use this Image for Next Edit")
|
| 103 |
|
| 104 |
# --- Event Handlers ---
|
| 105 |
-
|
| 106 |
def unified_generator(
|
| 107 |
prompt: str,
|
| 108 |
single_image: Optional[str],
|
|
@@ -126,10 +112,8 @@ with gr.Blocks(theme=gr.themes.Citrus()) as demo:
|
|
| 126 |
outputs=[output_image],
|
| 127 |
)
|
| 128 |
|
| 129 |
-
# Corrected handler for the continuous editing loop.
|
| 130 |
-
# It takes the output image and directly returns it to be used as the input.
|
| 131 |
use_image_button.click(
|
| 132 |
-
lambda img: img,
|
| 133 |
inputs=[output_image],
|
| 134 |
outputs=[image_input]
|
| 135 |
)
|
|
|
|
| 4 |
from typing import Optional, List
|
| 5 |
from huggingface_hub import whoami
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
fal_client.api_key = FAL_KEY
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def verify_pro_status(token: Optional[gr.OAuthToken]) -> bool:
|
| 11 |
"""Verifies if the user is a Hugging Face PRO user using their token."""
|
|
|
|
| 22 |
|
| 23 |
def run_single_image_logic(prompt: str, image: Optional[str] = None) -> str:
|
| 24 |
"""Handles text-to-image or single image-to-image and returns a single URL string."""
|
|
|
|
| 25 |
if image:
|
| 26 |
image_url = fal_client.upload_file(image)
|
| 27 |
result = fal_client.run(
|
|
|
|
| 39 |
"""
|
| 40 |
Handles multi-image editing by sending a list of URLs in a single API call.
|
| 41 |
"""
|
|
|
|
| 42 |
if not images:
|
| 43 |
raise gr.Error("Please upload at least one image in the 'Multiple Images' tab.")
|
| 44 |
|
|
|
|
| 63 |
main_interface = gr.Column(visible=False)
|
| 64 |
|
| 65 |
with main_interface:
|
| 66 |
+
gr.Markdown("## Thanks for being a PRO! 🤗")
|
| 67 |
with gr.Row():
|
| 68 |
with gr.Column(scale=1):
|
| 69 |
active_tab_state = gr.State(value="single")
|
|
|
|
| 84 |
)
|
| 85 |
generate_button = gr.Button("Generate", variant="primary")
|
| 86 |
|
|
|
|
| 87 |
with gr.Column(scale=1):
|
| 88 |
output_image = gr.Image(label="Output", interactive=False)
|
| 89 |
use_image_button = gr.Button("♻️ Use this Image for Next Edit")
|
| 90 |
|
| 91 |
# --- Event Handlers ---
|
|
|
|
| 92 |
def unified_generator(
|
| 93 |
prompt: str,
|
| 94 |
single_image: Optional[str],
|
|
|
|
| 112 |
outputs=[output_image],
|
| 113 |
)
|
| 114 |
|
|
|
|
|
|
|
| 115 |
use_image_button.click(
|
| 116 |
+
lambda img: img,
|
| 117 |
inputs=[output_image],
|
| 118 |
outputs=[image_input]
|
| 119 |
)
|