Spaces:
Sleeping
Sleeping
geeksiddhant
commited on
Commit
•
3b73399
1
Parent(s):
00731fc
Update app.py
Browse files
app.py
CHANGED
@@ -5,12 +5,15 @@ from PIL import Image
|
|
5 |
import io
|
6 |
import json
|
7 |
|
8 |
-
def call_api_and_generate_image(api_key, negative_prompt, positive_prompt, controlnet_image):
|
9 |
if not api_key:
|
10 |
return None, "Error: API key is required. Please provide a valid API key."
|
11 |
|
|
|
|
|
|
|
12 |
resp = requests.post(
|
13 |
-
|
14 |
headers={"Authorization": f"Api-Key {api_key}"},
|
15 |
json={
|
16 |
'workflow_values': {
|
@@ -30,9 +33,9 @@ def call_api_and_generate_image(api_key, negative_prompt, positive_prompt, contr
|
|
30 |
image = Image.open(io.BytesIO(image_data))
|
31 |
return image, json.dumps(result, indent=2)
|
32 |
|
33 |
-
def generate_image(api_key, negative_prompt, positive_prompt, controlnet_image):
|
34 |
try:
|
35 |
-
return call_api_and_generate_image(api_key, negative_prompt, positive_prompt, controlnet_image)
|
36 |
except Exception as e:
|
37 |
return None, f"Error: {str(e)}"
|
38 |
|
@@ -40,6 +43,7 @@ def generate_image(api_key, negative_prompt, positive_prompt, controlnet_image):
|
|
40 |
iface = gr.Interface(
|
41 |
fn=generate_image,
|
42 |
inputs=[
|
|
|
43 |
gr.Textbox(label="API Key", placeholder="Enter your API key here"),
|
44 |
gr.Textbox(label="Negative Prompt", value="blurry, text, low quality", placeholder="Enter negative prompt here..."),
|
45 |
gr.Textbox(label="Positive Prompt", value="An igloo on a snowy day, 4k, hd", placeholder="Enter positive prompt here..."),
|
@@ -50,7 +54,7 @@ iface = gr.Interface(
|
|
50 |
gr.Textbox(label="API Response JSON", lines=10)
|
51 |
],
|
52 |
title="Image Generation with API",
|
53 |
-
description="Enter your API key and prompts to generate an image using the provided API."
|
54 |
)
|
55 |
|
56 |
# Launch the interface
|
|
|
5 |
import io
|
6 |
import json
|
7 |
|
8 |
+
def call_api_and_generate_image(api_url, api_key, negative_prompt, positive_prompt, controlnet_image):
|
9 |
if not api_key:
|
10 |
return None, "Error: API key is required. Please provide a valid API key."
|
11 |
|
12 |
+
if not api_url:
|
13 |
+
return None, "Error: API URL is required. Please provide a valid API URL."
|
14 |
+
|
15 |
resp = requests.post(
|
16 |
+
api_url,
|
17 |
headers={"Authorization": f"Api-Key {api_key}"},
|
18 |
json={
|
19 |
'workflow_values': {
|
|
|
33 |
image = Image.open(io.BytesIO(image_data))
|
34 |
return image, json.dumps(result, indent=2)
|
35 |
|
36 |
+
def generate_image(api_url, api_key, negative_prompt, positive_prompt, controlnet_image):
|
37 |
try:
|
38 |
+
return call_api_and_generate_image(api_url, api_key, negative_prompt, positive_prompt, controlnet_image)
|
39 |
except Exception as e:
|
40 |
return None, f"Error: {str(e)}"
|
41 |
|
|
|
43 |
iface = gr.Interface(
|
44 |
fn=generate_image,
|
45 |
inputs=[
|
46 |
+
gr.Textbox(label="API URL", placeholder="Enter the API URL here", value="https://model-5qe9kjp3.api.baseten.co/development/predict"),
|
47 |
gr.Textbox(label="API Key", placeholder="Enter your API key here"),
|
48 |
gr.Textbox(label="Negative Prompt", value="blurry, text, low quality", placeholder="Enter negative prompt here..."),
|
49 |
gr.Textbox(label="Positive Prompt", value="An igloo on a snowy day, 4k, hd", placeholder="Enter positive prompt here..."),
|
|
|
54 |
gr.Textbox(label="API Response JSON", lines=10)
|
55 |
],
|
56 |
title="Image Generation with API",
|
57 |
+
description="Enter the API URL, your API key, and prompts to generate an image using the provided API."
|
58 |
)
|
59 |
|
60 |
# Launch the interface
|