Spaces:
Runtime error
Runtime error
fix
Browse files
app.py
CHANGED
@@ -11,13 +11,13 @@ logging.basicConfig(level=logging.INFO)
|
|
11 |
|
12 |
|
13 |
def sanitize_filename(prompt):
|
14 |
-
sanitized = re.sub(r
|
15 |
-
sanitized = re.sub(r
|
16 |
-
sanitized = sanitized.strip(
|
17 |
return sanitized[:50]
|
18 |
|
19 |
|
20 |
-
def generate_image(api_key, prompt, file_format):
|
21 |
if not api_key:
|
22 |
raise gr.Error("API key is required. Please enter your OpenAI API key.")
|
23 |
|
@@ -33,7 +33,7 @@ def generate_image(api_key, prompt, file_format):
|
|
33 |
response = client.images.generate(
|
34 |
model="dall-e-3",
|
35 |
prompt=prompt,
|
36 |
-
size=
|
37 |
quality="standard",
|
38 |
n=1,
|
39 |
)
|
@@ -74,9 +74,8 @@ with gr.Blocks() as demo:
|
|
74 |
|
75 |
**Please Note:**
|
76 |
1. Image generation typically takes around 30 seconds per image.
|
77 |
-
2.
|
78 |
-
3.
|
79 |
-
4. We are not responsible for any failures in image generation. Use this application at your own risk.
|
80 |
""")
|
81 |
|
82 |
with gr.Row():
|
@@ -86,6 +85,11 @@ with gr.Blocks() as demo:
|
|
86 |
label="Enter your prompt", placeholder="e.g., a white siamese cat"
|
87 |
)
|
88 |
file_format = gr.Radio(["webp", "png"], label="File Format", value="webp")
|
|
|
|
|
|
|
|
|
|
|
89 |
submit_button = gr.Button("Generate Image")
|
90 |
|
91 |
with gr.Column(scale=1):
|
@@ -93,7 +97,7 @@ with gr.Blocks() as demo:
|
|
93 |
|
94 |
submit_button.click(
|
95 |
generate_image,
|
96 |
-
inputs=[api_key_input, prompt_input, file_format],
|
97 |
outputs=image_output,
|
98 |
)
|
99 |
|
|
|
11 |
|
12 |
|
13 |
def sanitize_filename(prompt):
|
14 |
+
sanitized = re.sub(r"[^\w\-]", "_", prompt)
|
15 |
+
sanitized = re.sub(r"_+", "_", sanitized)
|
16 |
+
sanitized = sanitized.strip("_")
|
17 |
return sanitized[:50]
|
18 |
|
19 |
|
20 |
+
def generate_image(api_key, prompt, file_format, image_size):
|
21 |
if not api_key:
|
22 |
raise gr.Error("API key is required. Please enter your OpenAI API key.")
|
23 |
|
|
|
33 |
response = client.images.generate(
|
34 |
model="dall-e-3",
|
35 |
prompt=prompt,
|
36 |
+
size=image_size,
|
37 |
quality="standard",
|
38 |
n=1,
|
39 |
)
|
|
|
74 |
|
75 |
**Please Note:**
|
76 |
1. Image generation typically takes around 30 seconds per image.
|
77 |
+
2. Pricing varies based on image size. For the most up-to-date pricing information, please visit the [OpenAI Pricing Page](https://openai.com/api/pricing/).
|
78 |
+
3. We are not responsible for any failures in image generation. Use this application at your own risk.
|
|
|
79 |
""")
|
80 |
|
81 |
with gr.Row():
|
|
|
85 |
label="Enter your prompt", placeholder="e.g., a white siamese cat"
|
86 |
)
|
87 |
file_format = gr.Radio(["webp", "png"], label="File Format", value="webp")
|
88 |
+
image_size = gr.Radio(
|
89 |
+
["1024x1024", "1024x1792", "1792x1024"],
|
90 |
+
label="Image Size",
|
91 |
+
value="1024x1024",
|
92 |
+
)
|
93 |
submit_button = gr.Button("Generate Image")
|
94 |
|
95 |
with gr.Column(scale=1):
|
|
|
97 |
|
98 |
submit_button.click(
|
99 |
generate_image,
|
100 |
+
inputs=[api_key_input, prompt_input, file_format, image_size],
|
101 |
outputs=image_output,
|
102 |
)
|
103 |
|