Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,40 @@ from utils.gradio_helpers import parse_outputs, process_outputs
|
|
| 9 |
names = ['image', 'rotate_pitch', 'rotate_yaw', 'rotate_roll', 'blink', 'eyebrow', 'wink', 'pupil_x', 'pupil_y', 'aaa', 'eee', 'woo', 'smile', 'src_ratio', 'sample_ratio', 'crop_factor', 'output_format', 'output_quality']
|
| 10 |
|
| 11 |
def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def check_password(password):
|
| 15 |
return password == "pixo"
|
|
|
|
| 9 |
names = ['image', 'rotate_pitch', 'rotate_yaw', 'rotate_roll', 'blink', 'eyebrow', 'wink', 'pupil_x', 'pupil_y', 'aaa', 'eee', 'woo', 'smile', 'src_ratio', 'sample_ratio', 'crop_factor', 'output_format', 'output_quality']
|
| 10 |
|
| 11 |
def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
|
| 12 |
+
headers = {'Content-Type': 'application/json'}
|
| 13 |
+
|
| 14 |
+
payload = {"input": {}}
|
| 15 |
+
|
| 16 |
+
base_url = "http://0.0.0.0:7860"
|
| 17 |
+
for i, key in enumerate(names):
|
| 18 |
+
value = args[i]
|
| 19 |
+
if value and (os.path.exists(str(value))):
|
| 20 |
+
value = f"{base_url}/file=" + value
|
| 21 |
+
if value is not None and value != "":
|
| 22 |
+
payload["input"][key] = value
|
| 23 |
+
|
| 24 |
+
response = requests.post("http://0.0.0.0:5000/predictions", headers=headers, json=payload)
|
| 25 |
+
|
| 26 |
+
if response.status_code == 201:
|
| 27 |
+
follow_up_url = response.json()["urls"]["get"]
|
| 28 |
+
response = requests.get(follow_up_url, headers=headers)
|
| 29 |
+
while response.json()["status"] != "succeeded":
|
| 30 |
+
if response.json()["status"] == "failed":
|
| 31 |
+
raise gr.Error("The submission failed!")
|
| 32 |
+
response = requests.get(follow_up_url, headers=headers)
|
| 33 |
+
time.sleep(1)
|
| 34 |
+
if response.status_code == 200:
|
| 35 |
+
json_response = response.json()
|
| 36 |
+
if(outputs[0].get_config()["name"] == "json"):
|
| 37 |
+
return json_response["output"]
|
| 38 |
+
predict_outputs = parse_outputs(json_response["output"])
|
| 39 |
+
processed_outputs = process_outputs(predict_outputs)
|
| 40 |
+
|
| 41 |
+
return tuple(processed_outputs) if len(processed_outputs) > 1 else processed_outputs[0]
|
| 42 |
+
else:
|
| 43 |
+
if(response.status_code == 409):
|
| 44 |
+
raise gr.Error(f"Sorry, the Cog image is still processing. Try again in a bit.")
|
| 45 |
+
raise gr.Error(f"The submission failed! Error: {response.status_code}")
|
| 46 |
|
| 47 |
def check_password(password):
|
| 48 |
return password == "pixo"
|