Update app.py
Browse filesadd quality、size and style
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import requests
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
def generate_image(prompt, api_key, request_url):
|
| 5 |
headers = {
|
| 6 |
"Authorization": f"Bearer {api_key}",
|
| 7 |
"Content-Type": "application/json",
|
|
@@ -9,8 +9,9 @@ def generate_image(prompt, api_key, request_url):
|
|
| 9 |
data = {
|
| 10 |
"prompt": prompt,
|
| 11 |
"model": "dall-e-3",
|
| 12 |
-
"quality":
|
| 13 |
-
"size":
|
|
|
|
| 14 |
"num_images": 1,
|
| 15 |
}
|
| 16 |
response = requests.post(request_url, headers=headers, json=data)
|
|
@@ -21,23 +22,22 @@ def generate_image(prompt, api_key, request_url):
|
|
| 21 |
|
| 22 |
return image_url
|
| 23 |
|
| 24 |
-
css = """
|
| 25 |
-
footer {visibility: hidden !important;}
|
| 26 |
-
"""
|
| 27 |
-
|
| 28 |
# Create the interface using Gradio
|
| 29 |
-
with gr.Blocks(
|
| 30 |
with gr.Row():
|
| 31 |
gr.Markdown("# <center> OpenAI dall-e-3 API with Gradio </center>")
|
| 32 |
-
gr.Markdown("This demo uses the OpenAI dall-e-3 API to generate an image from text. You get free session key from https://dongsiqie.me/sess")
|
| 33 |
with gr.Row():
|
| 34 |
api_key_input = gr.Textbox(label="API Key", type="password")
|
| 35 |
request_url_input = gr.Textbox(label="Request URL", value="https://api.openai.com/v1/images/generations")
|
|
|
|
|
|
|
|
|
|
| 36 |
with gr.Row():
|
| 37 |
-
prompt_input = gr.Textbox(label="Image Description",value="A furry, long-haired cat with distinctive orange and white stripes.")
|
| 38 |
submit_btn = gr.Button("Generate Image", variant='primary')
|
| 39 |
image_output = gr.Image(label="Generated Image")
|
| 40 |
|
| 41 |
-
submit_btn.click(fn=generate_image, inputs=[prompt_input, api_key_input, request_url_input], outputs=image_output)
|
| 42 |
|
| 43 |
demo.launch()
|
|
|
|
| 1 |
import requests
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
def generate_image(prompt, quality, size, style, api_key, request_url):
|
| 5 |
headers = {
|
| 6 |
"Authorization": f"Bearer {api_key}",
|
| 7 |
"Content-Type": "application/json",
|
|
|
|
| 9 |
data = {
|
| 10 |
"prompt": prompt,
|
| 11 |
"model": "dall-e-3",
|
| 12 |
+
"quality": quality,
|
| 13 |
+
"size": size,
|
| 14 |
+
"style": style,
|
| 15 |
"num_images": 1,
|
| 16 |
}
|
| 17 |
response = requests.post(request_url, headers=headers, json=data)
|
|
|
|
| 22 |
|
| 23 |
return image_url
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Create the interface using Gradio
|
| 26 |
+
with gr.Blocks() as demo:
|
| 27 |
with gr.Row():
|
| 28 |
gr.Markdown("# <center> OpenAI dall-e-3 API with Gradio </center>")
|
| 29 |
+
gr.Markdown("This demo uses the OpenAI dall-e-3 API to generate an image from text. You get a free session key from https://dongsiqie.me/sess")
|
| 30 |
with gr.Row():
|
| 31 |
api_key_input = gr.Textbox(label="API Key", type="password")
|
| 32 |
request_url_input = gr.Textbox(label="Request URL", value="https://api.openai.com/v1/images/generations")
|
| 33 |
+
quality_input = gr.Dropdown(label="Quality", choices=["standard", "hd"], value="standard")
|
| 34 |
+
size_input = gr.Dropdown(label="Size", choices=["1792x1024", "1024x1024", "1024x1792"], value="1792x1024")
|
| 35 |
+
style_input = gr.Dropdown(label="Style", choices=["vivid", "natural"], value="vivid")
|
| 36 |
with gr.Row():
|
| 37 |
+
prompt_input = gr.Textbox(label="Image Description", value="A furry, long-haired cat with distinctive orange and white stripes.")
|
| 38 |
submit_btn = gr.Button("Generate Image", variant='primary')
|
| 39 |
image_output = gr.Image(label="Generated Image")
|
| 40 |
|
| 41 |
+
submit_btn.click(fn=generate_image, inputs=[prompt_input, quality_input, size_input, style_input, api_key_input, request_url_input], outputs=image_output)
|
| 42 |
|
| 43 |
demo.launch()
|