Spaces:
Running
on
A10G
Running
on
A10G
Update app.py
Browse files
app.py
CHANGED
@@ -22,62 +22,67 @@ from utils.gradio_helpers import parse_outputs, process_outputs
|
|
22 |
names = ['prompt', 'negative_prompt', 'subject', 'number_of_outputs', 'number_of_images_per_pose', 'randomise_poses', 'output_format', 'output_quality', 'seed']
|
23 |
|
24 |
def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
|
25 |
-
|
26 |
print(f"""
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
32 |
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
|
45 |
|
46 |
-
|
47 |
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
|
57 |
-
|
58 |
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
response = requests.get(follow_up_url, headers=headers)
|
63 |
-
while response.json()["status"] != "succeeded":
|
64 |
-
if response.json()["status"] == "failed":
|
65 |
-
raise gr.Error("The submission failed!")
|
66 |
response = requests.get(follow_up_url, headers=headers)
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
title = "Demo for consistent-character cog image by fofr"
|
83 |
description = "Create images of a given character in different poses • running cog image by fofr"
|
|
|
22 |
names = ['prompt', 'negative_prompt', 'subject', 'number_of_outputs', 'number_of_images_per_pose', 'randomise_poses', 'output_format', 'output_quality', 'seed']
|
23 |
|
24 |
def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
|
|
|
25 |
print(f"""
|
26 |
+
—/n
|
27 |
+
{args[0]}
|
28 |
+
""")
|
29 |
+
|
30 |
+
try:
|
31 |
+
|
32 |
+
is_safe = safety_check(args[0])
|
33 |
+
print(is_safe)
|
34 |
|
35 |
+
match = re.search(r'\bYes\b', is_safe)
|
36 |
|
37 |
+
if match:
|
38 |
+
status = 'Yes'
|
39 |
+
else:
|
40 |
+
status = None
|
41 |
|
42 |
+
if status == "Yes" :
|
43 |
+
raise gr.Error("Don't ask for such things.")
|
44 |
+
else:
|
45 |
|
46 |
+
headers = {'Content-Type': 'application/json'}
|
47 |
|
48 |
+
payload = {"input": {}}
|
49 |
|
50 |
|
51 |
+
base_url = "http://0.0.0.0:7860"
|
52 |
+
for i, key in enumerate(names):
|
53 |
+
value = args[i]
|
54 |
+
if value and (os.path.exists(str(value))):
|
55 |
+
value = f"{base_url}/file=" + value
|
56 |
+
if value is not None and value != "":
|
57 |
+
payload["input"][key] = value
|
58 |
|
59 |
+
response = requests.post("http://0.0.0.0:5000/predictions", headers=headers, json=payload)
|
60 |
|
61 |
|
62 |
+
if response.status_code == 201:
|
63 |
+
follow_up_url = response.json()["urls"]["get"]
|
|
|
|
|
|
|
|
|
64 |
response = requests.get(follow_up_url, headers=headers)
|
65 |
+
while response.json()["status"] != "succeeded":
|
66 |
+
if response.json()["status"] == "failed":
|
67 |
+
raise gr.Error("The submission failed!")
|
68 |
+
response = requests.get(follow_up_url, headers=headers)
|
69 |
+
time.sleep(1)
|
70 |
+
if response.status_code == 200:
|
71 |
+
json_response = response.json()
|
72 |
+
#If the output component is JSON return the entire output response
|
73 |
+
if(outputs[0].get_config()["name"] == "json"):
|
74 |
+
return json_response["output"]
|
75 |
+
predict_outputs = parse_outputs(json_response["output"])
|
76 |
+
processed_outputs = process_outputs(predict_outputs)
|
77 |
+
return tuple(processed_outputs) if len(processed_outputs) > 1 else processed_outputs[0]
|
78 |
+
else:
|
79 |
+
if(response.status_code == 409):
|
80 |
+
raise gr.Error(f"Sorry, the Cog image is still processing. Try again in a bit.")
|
81 |
+
raise gr.Error(f"The submission failed! Error: {response.status_code}")
|
82 |
+
|
83 |
+
except Exception as e:
|
84 |
+
# Handle any other type of error
|
85 |
+
raise gr.Error(f"An error occurred: {e}")
|
86 |
|
87 |
title = "Demo for consistent-character cog image by fofr"
|
88 |
description = "Create images of a given character in different poses • running cog image by fofr"
|