Update app.py
Browse files
app.py
CHANGED
@@ -8,14 +8,25 @@ hf_token = os.environ.get('HF_TOKEN')
|
|
8 |
sdxl_client = Client("https://fffiloni-sdxl-dpo.hf.space/")
|
9 |
faceswap_client = Client("https://fffiloni-deepfakeai.hf.space/", hf_token=hf_token)
|
10 |
|
11 |
-
def
|
12 |
-
# Generate Image from SDXL
|
13 |
-
gr.Info("Generating SDXL image first ...")
|
14 |
sdxl_result = sdxl_client.predict(
|
15 |
prompt_in,
|
16 |
api_name="/infer"
|
17 |
)
|
|
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
unique_id = str(uuid.uuid4())
|
20 |
|
21 |
# Face Swap
|
@@ -45,10 +56,11 @@ with gr.Blocks(css=css) as demo:
|
|
45 |
<h2 style="text-align: center;">Portrait Maker</h2>
|
46 |
""")
|
47 |
with gr.Row():
|
48 |
-
with gr.
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
52 |
with gr.Column():
|
53 |
result = gr.Image(label="Result")
|
54 |
|
|
|
8 |
sdxl_client = Client("https://fffiloni-sdxl-dpo.hf.space/")
|
9 |
faceswap_client = Client("https://fffiloni-deepfakeai.hf.space/", hf_token=hf_token)
|
10 |
|
11 |
+
def get_sdxl(prompt_in):
|
|
|
|
|
12 |
sdxl_result = sdxl_client.predict(
|
13 |
prompt_in,
|
14 |
api_name="/infer"
|
15 |
)
|
16 |
+
return sdxl_result
|
17 |
|
18 |
+
def infer(portrait_in, prompt_in):
|
19 |
+
# Generate Image from SDXL
|
20 |
+
gr.Info("Generating SDXL image first ...")
|
21 |
+
# Keep trying the operation until it succeeds without raising an exception
|
22 |
+
while True:
|
23 |
+
try:
|
24 |
+
sdxl_result = get_sdxl(prompt_in)
|
25 |
+
break # Exit the while loop if the operation succeeded
|
26 |
+
except Exception as e:
|
27 |
+
print(f"Operation failed with error: {e}")
|
28 |
+
time.sleep(3) # Wait for 5 seconds before attempting again
|
29 |
+
|
30 |
unique_id = str(uuid.uuid4())
|
31 |
|
32 |
# Face Swap
|
|
|
56 |
<h2 style="text-align: center;">Portrait Maker</h2>
|
57 |
""")
|
58 |
with gr.Row():
|
59 |
+
with gr.Group():
|
60 |
+
with gr.Column():
|
61 |
+
portrait_in = gr.Image(label="Your face portrait", type="filepath")
|
62 |
+
prompt_in = gr.Textbox(label="Prompt to desired portrait using your own face")
|
63 |
+
submit_btn = gr.Button("Submit")
|
64 |
with gr.Column():
|
65 |
result = gr.Image(label="Result")
|
66 |
|