miittnnss commited on
Commit
57d84d6
·
1 Parent(s): dd5f052

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -34,11 +34,15 @@ def extend_prompt(input_text):
34
 
35
  payload = {"inputs": input_text}
36
 
37
- response = requests.post(API_URL, headers=HEADERS, json=payload)
38
- response.raise_for_status()
 
39
 
40
- extended_prompt = response.content
41
- return str(extended_prompt)
 
 
 
42
 
43
  def generate_image(prompt, selected_model, is_negative=False, steps=1, cfg_scale=6, seed=None):
44
  if not prompt.strip():
@@ -55,12 +59,16 @@ def generate_image(prompt, selected_model, is_negative=False, steps=1, cfg_scale
55
  "seed": seed if seed is not None else random.randint(-1, 2147483647)
56
  }
57
 
58
- response = requests.post(API_URL, headers=HEADERS, json=payload)
59
- response.raise_for_status()
 
60
 
61
- image_bytes = io.BytesIO(response.content)
62
- image = Image.open(image_bytes)
63
- return image
 
 
 
64
 
65
  with gr.Blocks(theme="soft") as playground:
66
  gr.HTML(
 
34
 
35
  payload = {"inputs": input_text}
36
 
37
+ try:
38
+ response = requests.post(API_URL, headers=HEADERS, json=payload)
39
+ response.raise_for_status()
40
 
41
+ extended_prompt = response.content
42
+ return str(extended_prompt)
43
+
44
+ except requests.exceptions.RequestException as e:
45
+ return None
46
 
47
  def generate_image(prompt, selected_model, is_negative=False, steps=1, cfg_scale=6, seed=None):
48
  if not prompt.strip():
 
59
  "seed": seed if seed is not None else random.randint(-1, 2147483647)
60
  }
61
 
62
+ try:
63
+ response = requests.post(API_URL, headers=HEADERS, json=payload)
64
+ response.raise_for_status()
65
 
66
+ image_bytes = io.BytesIO(response.content)
67
+ image = Image.open(image_bytes)
68
+ return image
69
+
70
+ except requests.exceptions.RequestException as e:
71
+ raise gr.Error(e)
72
 
73
  with gr.Blocks(theme="soft") as playground:
74
  gr.HTML(