Update app.py
Browse files
app.py
CHANGED
@@ -34,11 +34,15 @@ def extend_prompt(input_text):
|
|
34 |
|
35 |
payload = {"inputs": input_text}
|
36 |
|
37 |
-
|
38 |
-
|
|
|
39 |
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
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 |
-
|
59 |
-
|
|
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
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(
|