Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,16 +5,24 @@ from pathlib import Path
|
|
| 5 |
from PIL import Image
|
| 6 |
import gradio as gr
|
| 7 |
from huggingface_hub import hf_hub_download
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
from nodes import NODE_CLASS_MAPPINGS
|
| 9 |
import folder_paths
|
| 10 |
|
| 11 |
-
#
|
| 12 |
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
|
| 13 |
output_dir = os.path.join(BASE_DIR, "output")
|
| 14 |
os.makedirs(output_dir, exist_ok=True)
|
| 15 |
folder_paths.set_output_directory(output_dir)
|
| 16 |
|
| 17 |
-
# Download
|
| 18 |
def download_models():
|
| 19 |
models = [
|
| 20 |
("black-forest-labs/FLUX.1-Redux-dev", "flux1-redux-dev.safetensors", "style_models"),
|
|
@@ -33,7 +41,7 @@ def download_models():
|
|
| 33 |
hf_hub_download(repo_id=repo_id, filename=filename, local_dir=model_dir)
|
| 34 |
folder_paths.add_model_folder_path(model_type, model_dir)
|
| 35 |
|
| 36 |
-
# Load custom nodes
|
| 37 |
def import_custom_nodes():
|
| 38 |
import asyncio
|
| 39 |
import execution
|
|
@@ -47,7 +55,7 @@ def import_custom_nodes():
|
|
| 47 |
execution.PromptQueue(server_instance)
|
| 48 |
init_extra_nodes()
|
| 49 |
|
| 50 |
-
# Main function to execute the workflow and generate an image
|
| 51 |
def generate_image(prompt, input_image, lora_weight, guidance, downsampling_factor, weight, seed, width, height, batch_size, steps):
|
| 52 |
import_custom_nodes()
|
| 53 |
|
|
@@ -184,7 +192,7 @@ def generate_image(prompt, input_image, lora_weight, guidance, downsampling_fact
|
|
| 184 |
print(f"Error during generation: {str(e)}")
|
| 185 |
return None
|
| 186 |
|
| 187 |
-
# Gradio Interface
|
| 188 |
with gr.Blocks() as app:
|
| 189 |
gr.Markdown("# FLUX Redux Image Generator")
|
| 190 |
|
|
|
|
| 5 |
from PIL import Image
|
| 6 |
import gradio as gr
|
| 7 |
from huggingface_hub import hf_hub_download
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
# 1. Configura莽茫o de Caminhos
|
| 11 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 12 |
+
comfyui_path = os.path.join(current_dir, "ComfyUI")
|
| 13 |
+
sys.path.append(comfyui_path)
|
| 14 |
+
|
| 15 |
+
# 2. Imports do ComfyUI
|
| 16 |
from nodes import NODE_CLASS_MAPPINGS
|
| 17 |
import folder_paths
|
| 18 |
|
| 19 |
+
# 3. Configura莽茫o de Diret贸rios
|
| 20 |
BASE_DIR = os.path.dirname(os.path.realpath(__file__))
|
| 21 |
output_dir = os.path.join(BASE_DIR, "output")
|
| 22 |
os.makedirs(output_dir, exist_ok=True)
|
| 23 |
folder_paths.set_output_directory(output_dir)
|
| 24 |
|
| 25 |
+
# 4. Download de Modelos
|
| 26 |
def download_models():
|
| 27 |
models = [
|
| 28 |
("black-forest-labs/FLUX.1-Redux-dev", "flux1-redux-dev.safetensors", "style_models"),
|
|
|
|
| 41 |
hf_hub_download(repo_id=repo_id, filename=filename, local_dir=model_dir)
|
| 42 |
folder_paths.add_model_folder_path(model_type, model_dir)
|
| 43 |
|
| 44 |
+
# 5. Load custom nodes
|
| 45 |
def import_custom_nodes():
|
| 46 |
import asyncio
|
| 47 |
import execution
|
|
|
|
| 55 |
execution.PromptQueue(server_instance)
|
| 56 |
init_extra_nodes()
|
| 57 |
|
| 58 |
+
# 6. Main function to execute the workflow and generate an image
|
| 59 |
def generate_image(prompt, input_image, lora_weight, guidance, downsampling_factor, weight, seed, width, height, batch_size, steps):
|
| 60 |
import_custom_nodes()
|
| 61 |
|
|
|
|
| 192 |
print(f"Error during generation: {str(e)}")
|
| 193 |
return None
|
| 194 |
|
| 195 |
+
# 7. Gradio Interface
|
| 196 |
with gr.Blocks() as app:
|
| 197 |
gr.Markdown("# FLUX Redux Image Generator")
|
| 198 |
|