Update app.py
Browse files
app.py
CHANGED
|
@@ -3,8 +3,8 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import base64
|
| 5 |
from io import BytesIO
|
| 6 |
-
from PIL import Image
|
| 7 |
-
import random
|
| 8 |
|
| 9 |
# Get API key from environment variable
|
| 10 |
api_key = os.environ.get("NVCF_API_KEY")
|
|
@@ -22,8 +22,10 @@ headers = {
|
|
| 22 |
|
| 23 |
# Function to generate image using the API
|
| 24 |
def generate_image(prompt, negative_prompt, sampler, seed, guidance_scale, inference_steps):
|
| 25 |
-
|
|
|
|
| 26 |
seed = random.randint(1, 4294967296)
|
|
|
|
| 27 |
payload = {
|
| 28 |
"prompt": prompt,
|
| 29 |
"negative_prompt": negative_prompt,
|
|
@@ -66,9 +68,9 @@ iface = gr.Interface(
|
|
| 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="DDIM"),
|
| 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 |
description = """
|
|
|
|
| 3 |
import requests
|
| 4 |
import base64
|
| 5 |
from io import BytesIO
|
| 6 |
+
from PIL import Image
|
| 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 |
+
# Validate and adjust seed value
|
| 26 |
+
if seed is None or seed <= 0 or seed > 4294967296:
|
| 27 |
seed = random.randint(1, 4294967296)
|
| 28 |
+
|
| 29 |
payload = {
|
| 30 |
"prompt": prompt,
|
| 31 |
"negative_prompt": negative_prompt,
|
|
|
|
| 68 |
gr.Textbox(label="Prompt", placeholder="Describe the image you want to generate"),
|
| 69 |
gr.Textbox(label="Negative Prompt", placeholder="What should not be in the image"),
|
| 70 |
gr.Dropdown(label="Sampler", choices=["DPM", "EulerA", "LMS", "DDIM"], value="DDIM"),
|
| 71 |
+
gr.Number(label="Seed", value=0, step=1), # Ensure seed is treated correctly
|
| 72 |
+
gr.Slider(label="Guidance Scale", minimum=1, maximum=9, value=5, step=1),
|
| 73 |
+
gr.Slider(label="Inference Steps", minimum=5, maximum=100, value=35, step=1)
|
| 74 |
],
|
| 75 |
outputs=gr.Image(label="Generated Image"),
|
| 76 |
description = """
|