Zeph27 commited on
Commit
291e480
·
1 Parent(s): a70a146
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ venv/
2
+ .env
app.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import asyncio
3
+ import fal_client
4
+ from dotenv import load_dotenv
5
+ import os
6
+ from pathlib import Path
7
+ import time
8
+
9
+ load_dotenv()
10
+ os.environ["FAL_KEY"] = os.getenv("FAL_API_KEY")
11
+
12
+ async def generate_paris_images(image1_path: str, image2_path: str, woman_prompt: str, man_prompt: str, batch_size: int, progress=gr.Progress()):
13
+ start_time = time.time()
14
+ print("Progress: 5% - Starting Paris image generation...")
15
+ progress(0.05, desc="Starting Paris image generation...")
16
+
17
+ # Upload all images in parallel
18
+ upload_tasks = [
19
+ fal_client.upload_file_async(str(image1_path)),
20
+ fal_client.upload_file_async(str(image2_path)),
21
+ fal_client.upload_file_async("test_images/woman.png"),
22
+ fal_client.upload_file_async("test_images/man.png"),
23
+ fal_client.upload_file_async("test_images/clipspace-mask-4736783.png"),
24
+ fal_client.upload_file_async("test_images/clipspace-mask-4722992.png")
25
+ ]
26
+
27
+ [image1_url, image2_url, woman_img, man_img, mask1_img, mask2_img] = await asyncio.gather(*upload_tasks)
28
+
29
+ print("Progress: 40% - Uploaded all images")
30
+ progress(0.4, desc="Uploaded all images")
31
+
32
+ handler = await fal_client.submit_async(
33
+ "comfy/LVE/paris-couple",
34
+ arguments={
35
+ "loadimage_1": image1_url,
36
+ "loadimage_2": image2_url,
37
+ "loadimage_3": woman_img,
38
+ "loadimage_4": mask1_img,
39
+ "loadimage_5": mask2_img,
40
+ "loadimage_6": man_img,
41
+ "woman_prompt": woman_prompt,
42
+ "man_prompt": man_prompt,
43
+ "batch_size": batch_size
44
+ }
45
+ )
46
+
47
+ print("Progress: 60% - Processing images...")
48
+ progress(0.6, desc="Processing images...")
49
+
50
+ result = await handler.get()
51
+ print(result)
52
+
53
+ end_time = time.time()
54
+ processing_time = end_time - start_time
55
+ print(f"Progress: 100% - Generation completed in {processing_time:.2f} seconds")
56
+ progress(1.0, desc=f"Generation completed in {processing_time:.2f} seconds")
57
+
58
+ # Return all generated image URLs and processing time
59
+ # Get the first key from outputs dynamically
60
+ return (
61
+ [img["url"] for img in result["outputs"][next(iter(result["outputs"]))]["images"]] if "outputs" in result and result["outputs"] else [],
62
+ f"Processing time: {processing_time:.2f} seconds"
63
+ )
64
+
65
+ with gr.Blocks() as demo:
66
+ with gr.Row():
67
+ image1_input = gr.Image(label="Upload Woman Image", type="filepath", value="test_images/user3-f.jpg")
68
+ image2_input = gr.Image(label="Upload Man Image", type="filepath", value="test_images/user3.jpg")
69
+
70
+ with gr.Row():
71
+ woman_prompt = gr.Textbox(
72
+ label="Woman Prompt",
73
+ value="Close-up, portrait photo, a woman, Paris nighttime romance scene, wearing an elegant black dress with a shawl, standing beneath the same canopy of twinkling lights along the Champs-Élysées, the Eiffel Tower glowing bright in the distance, soft mist rising from the street, looking at the camera."
74
+ )
75
+ man_prompt = gr.Textbox(
76
+ label="Man Prompt",
77
+ value="Close-up, portrait photo, a man, Paris nighttime romance scene, wearing a tailored suit with a crisp white shirt, standing beneath a canopy of twinkling lights along the Champs-Élysées, the Eiffel Tower glowing bright in the distance, soft mist rising from the street, looking at the camera."
78
+ )
79
+
80
+ batch_size = gr.Slider(minimum=1, maximum=8, value=4, step=1, label="Batch Size")
81
+
82
+ generate_btn = gr.Button("Generate")
83
+ image_output = gr.Gallery(label="Generated Image")
84
+ time_output = gr.Textbox(label="Processing Time")
85
+
86
+ generate_btn.click(
87
+ fn=generate_paris_images,
88
+ inputs=[image1_input, image2_input, woman_prompt, man_prompt, batch_size],
89
+ outputs=[image_output, time_output]
90
+ )
91
+
92
+ if __name__ == "__main__":
93
+ print("Starting Gradio interface...")
94
+ demo.launch()
fal_test.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import fal_client
3
+ from dotenv import load_dotenv
4
+ import os
5
+
6
+ load_dotenv()
7
+
8
+ os.environ["FAL_KEY"] = os.getenv("FAL_API_KEY")
9
+
10
+ async def subscribe():
11
+ handler = await fal_client.submit_async(
12
+ "comfy/LVE/fal-favourite",
13
+ arguments={
14
+ "loadimage_1": "https://v3.fal.media/files/tiger/jn66x0N2Xu_zxX8_GKXP7_A4%20-%202.png",
15
+ "loadimage_2": "https://fal.media/files/elephant/UX-Etn4FZUSbUqxLKihR1.png",
16
+ "loadimage_3": "https://fal.media/files/lion/CjubwDK_JC9TSy6E_Ck2O.png",
17
+ "loadimage_4": "https://fal.media/files/koala/4-4xrKSOZFxInqt0r-clj.png",
18
+ "loadimage_5": "https://fal.media/files/koala/xz9aEtyqSb9jhLIgvZfdr.png",
19
+ "loadimage_6": "https://fal.media/files/monkey/6703hkTCUCzXo7d43E4mQ.png",
20
+ "loadimage_7": "https://fal.media/files/zebra/c3lO_fvrSreL3ebz2xfFA.png",
21
+ "loadimage_8": "https://fal.media/files/lion/UgFgxIjafvBFlu78Pj8ZP.png",
22
+ "loadimage_9": "https://fal.media/files/monkey/UQqjW4UU1-FJLiTd8l_QH.png",
23
+ "loadimage_10": "https://fal.media/files/monkey/mGciMw0tNFVyLKEUrapWO.png",
24
+ "title": "our favourite things",
25
+ "text_1-1": "cat",
26
+ "text_1-2": "motorcycle",
27
+ "text_1-3": "cocktail",
28
+ "text_2-1": "book",
29
+ "text_2-2": "money",
30
+ "text_2-3": "mountain",
31
+ "text_3-1": "computer",
32
+ "text_3-2": "console",
33
+ "text_3-3": "rose",
34
+ "couple_name": "ELLS & MILLS"
35
+ },
36
+ )
37
+
38
+ async for event in handler.iter_events(with_logs=True):
39
+ print(event)
40
+
41
+ result = await handler.get()
42
+
43
+ print(result)
44
+
45
+
46
+ if __name__ == "__main__":
47
+ asyncio.run(subscribe())
img2img.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import fal_client
3
+ from dotenv import load_dotenv
4
+ import os
5
+
6
+ load_dotenv()
7
+
8
+ os.environ["FAL_KEY"] = os.getenv("FAL_API_KEY")
9
+
10
+ async def subscribe():
11
+ handler = await fal_client.submit_async(
12
+ "comfy/fal-ai/image-to-image",
13
+ arguments={
14
+ "loadimage_1": "https://fal.media/files/elephant/UX-Etn4FZUSbUqxLKihR1.png",
15
+ "prompt": "photograph of cat"
16
+ },
17
+ )
18
+
19
+ async for event in handler.iter_events(with_logs=True):
20
+ print(event)
21
+
22
+ result = await handler.get()
23
+
24
+ print(result)
25
+
26
+
27
+ if __name__ == "__main__":
28
+ asyncio.run(subscribe())
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fal-client
2
+ python-dotenv
3
+ gradio
schnell_test.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import fal_client
3
+ from dotenv import load_dotenv
4
+ import os
5
+
6
+ load_dotenv()
7
+
8
+ os.environ["FAL_KEY"] = os.getenv("FAL_API_KEY")
9
+
10
+ async def subscribe(keyword: str):
11
+ handler = await fal_client.submit_async(
12
+ "fal-ai/flux/schnell",
13
+ arguments={
14
+ "prompt": f"{keyword}, illustration style, white background, centered layout",
15
+ "image_size": "square_hd"
16
+ },
17
+ )
18
+
19
+ async for event in handler.iter_events(with_logs=True):
20
+ print(event)
21
+
22
+ result = await handler.get()
23
+
24
+ print(result["images"][0]["url"])
25
+
26
+ if __name__ == "__main__":
27
+ asyncio.run(subscribe("dog"))
test_images/clipspace-mask-4722992.png ADDED
test_images/clipspace-mask-4736783.png ADDED
test_images/man.png ADDED
test_images/user3-f.jpg ADDED
test_images/user3.jpg ADDED
test_images/woman.png ADDED
upload_test.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ import fal_client
3
+ import os
4
+
5
+ # Load environment variables from .env file
6
+ load_dotenv()
7
+
8
+ # The key in your .env file is FAL_API_KEY but fal_client expects FAL_KEY
9
+ os.environ["FAL_KEY"] = os.getenv("FAL_API_KEY")
10
+
11
+ url = fal_client.upload_file("A4 - 2.png")
12
+ print(url)