Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import requests
|
|
4 |
import base64
|
5 |
from io import BytesIO
|
6 |
from PIL import Image # Corrected import
|
|
|
7 |
|
8 |
# Get API key from environment variable
|
9 |
api_key = os.environ.get("NVCF_API_KEY")
|
@@ -21,6 +22,8 @@ headers = {
|
|
21 |
|
22 |
# Function to generate image using the API
|
23 |
def generate_image(prompt, negative_prompt, sampler, seed, guidance_scale, inference_steps):
|
|
|
|
|
24 |
payload = {
|
25 |
"prompt": prompt,
|
26 |
"negative_prompt": negative_prompt,
|
@@ -62,10 +65,10 @@ iface = gr.Interface(
|
|
62 |
inputs=[
|
63 |
gr.Textbox(label="Prompt", placeholder="Describe the image you want to generate"),
|
64 |
gr.Textbox(label="Negative Prompt", placeholder="What should not be in the image"),
|
65 |
-
gr.Dropdown(label="Sampler", choices=["DPM", "
|
66 |
gr.Number(label="Seed", value=0),
|
67 |
-
gr.Slider(label="Guidance Scale", minimum=
|
68 |
-
gr.Slider(label="Inference Steps", minimum=
|
69 |
],
|
70 |
outputs=gr.Image(label="Generated Image"),
|
71 |
)
|
|
|
4 |
import base64
|
5 |
from io import BytesIO
|
6 |
from PIL import Image # Corrected import
|
7 |
+
import random
|
8 |
|
9 |
# Get API key from environment variable
|
10 |
api_key = os.environ.get("NVCF_API_KEY")
|
|
|
22 |
|
23 |
# Function to generate image using the API
|
24 |
def generate_image(prompt, negative_prompt, sampler, seed, guidance_scale, inference_steps):
|
25 |
+
if seed is None or seed == 0:
|
26 |
+
seed = random.randint(11111111, 999999999999999)
|
27 |
payload = {
|
28 |
"prompt": prompt,
|
29 |
"negative_prompt": negative_prompt,
|
|
|
65 |
inputs=[
|
66 |
gr.Textbox(label="Prompt", placeholder="Describe the image you want to generate"),
|
67 |
gr.Textbox(label="Negative Prompt", placeholder="What should not be in the image"),
|
68 |
+
gr.Dropdown(label="Sampler", choices=["DPM", "EulerA", "LMS", "DDIM"], value="DPM"),
|
69 |
gr.Number(label="Seed", value=0),
|
70 |
+
gr.Slider(label="Guidance Scale", minimum=1, maximum=9, value=5),
|
71 |
+
gr.Slider(label="Inference Steps", minimum=5, maximum=100, value=35)
|
72 |
],
|
73 |
outputs=gr.Image(label="Generated Image"),
|
74 |
)
|