lichorosario commited on
Commit
69525dd
1 Parent(s): a322e72

feat: Handle exceptions when submitting requests to custom models and tile upscaler APIs

Browse files
Files changed (1) hide show
  1. app.py +41 -28
app.py CHANGED
@@ -52,10 +52,14 @@ def infer(selected_index, prompt, style_prompt, inf_steps, guidance_scale, width
52
  raise gr.Error("Failed to load client for " + custom_model_url)
53
 
54
 
55
- result = client_custom_model.submit(
56
- custom_model=custom_model,
57
- api_name="/load_model"
58
- )
 
 
 
 
59
  weight_name = result.result()[2]['value']
60
 
61
  if trigger_word and prompt.startswith(trigger_word):
@@ -67,19 +71,24 @@ def infer(selected_index, prompt, style_prompt, inf_steps, guidance_scale, width
67
  prompt_arr = [trigger_word, prompt, style_prompt]
68
  prompt = '. '.join([element.strip() for element in prompt_arr if element.strip() != ''])
69
 
70
- job = client_custom_model.submit(
71
- custom_model=custom_model,
72
- weight_name=weight_name,
73
- prompt=prompt,
74
- inf_steps=inf_steps,
75
- guidance_scale=guidance_scale,
76
- width=width,
77
- height=height,
78
- seed=seed,
79
- lora_weight=lora_weight,
80
- api_name="/infer"
81
- )
82
- result = job.result()
 
 
 
 
 
83
  new_result = result + (prompt, )
84
 
85
  return new_result
@@ -117,17 +126,21 @@ def upscale_image(image, resolution, num_inference_steps, strength, hdr, guidanc
117
  client_custom_model = None
118
  raise gr.Error("Failed to load client for " + tile_upscaler_url)
119
 
120
- result = client_tile_upscaler.predict(
121
- param_0=handle_file(image),
122
- param_1=resolution,
123
- param_2=num_inference_steps,
124
- param_3=strength,
125
- param_4=hdr,
126
- param_5=guidance_scale,
127
- param_6=controlnet_strength,
128
- param_7=scheduler_name,
129
- api_name="/wrapper"
130
- )
 
 
 
 
131
  return result
132
 
133
 
 
52
  raise gr.Error("Failed to load client for " + custom_model_url)
53
 
54
 
55
+ try:
56
+ result = client_custom_model.submit(
57
+ custom_model=custom_model,
58
+ api_name="/load_model"
59
+ )
60
+ except ValueError as e:
61
+ raise gr.Error(e)
62
+
63
  weight_name = result.result()[2]['value']
64
 
65
  if trigger_word and prompt.startswith(trigger_word):
 
71
  prompt_arr = [trigger_word, prompt, style_prompt]
72
  prompt = '. '.join([element.strip() for element in prompt_arr if element.strip() != ''])
73
 
74
+ try:
75
+ job = client_custom_model.submit(
76
+ custom_model=custom_model,
77
+ weight_name=weight_name,
78
+ prompt=prompt,
79
+ inf_steps=inf_steps,
80
+ guidance_scale=guidance_scale,
81
+ width=width,
82
+ height=height,
83
+ seed=seed,
84
+ lora_weight=lora_weight,
85
+ api_name="/infer"
86
+ )
87
+ result = job.result()
88
+ except ValueError as e:
89
+ raise gr.Error(e)
90
+
91
+
92
  new_result = result + (prompt, )
93
 
94
  return new_result
 
126
  client_custom_model = None
127
  raise gr.Error("Failed to load client for " + tile_upscaler_url)
128
 
129
+ try:
130
+ result = client_tile_upscaler.predict(
131
+ param_0=handle_file(image),
132
+ param_1=resolution,
133
+ param_2=num_inference_steps,
134
+ param_3=strength,
135
+ param_4=hdr,
136
+ param_5=guidance_scale,
137
+ param_6=controlnet_strength,
138
+ param_7=scheduler_name,
139
+ api_name="/wrapper"
140
+ )
141
+ except ValueError as e:
142
+ raise gr.Error(e)
143
+
144
  return result
145
 
146