Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,7 @@
|
|
| 1 |
-
import os
|
| 2 |
import requests
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
api_key
|
| 6 |
-
|
| 7 |
-
def generate_image(prompt, code):
|
| 8 |
-
if code != os.getenv("code"):
|
| 9 |
-
raise gr.Error("❗ Не верный ключ!")
|
| 10 |
-
return None
|
| 11 |
headers = {
|
| 12 |
"Authorization": f"Bearer {api_key}",
|
| 13 |
"Content-Type": "application/json",
|
|
@@ -16,25 +10,31 @@ def generate_image(prompt, code):
|
|
| 16 |
"prompt": prompt,
|
| 17 |
"num_images": 1,
|
| 18 |
}
|
| 19 |
-
response = requests.post(
|
| 20 |
response_json = response.json()
|
| 21 |
|
| 22 |
-
#
|
| 23 |
image_url = response_json["data"][0]["url"]
|
| 24 |
|
| 25 |
return image_url
|
|
|
|
| 26 |
css = """
|
| 27 |
footer {visibility: hidden !important;}
|
| 28 |
"""
|
| 29 |
-
|
|
|
|
| 30 |
with gr.Blocks(css=css, theme='YTheme/Sketch') as demo:
|
| 31 |
with gr.Row():
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
with gr.Row():
|
| 34 |
-
prompt_input = gr.Textbox(label="
|
| 35 |
-
submit_btn = gr.Button("
|
| 36 |
-
image_output = gr.Image(label="
|
| 37 |
|
| 38 |
-
submit_btn.click(fn=generate_image, inputs=[prompt_input,
|
| 39 |
|
| 40 |
-
demo.launch()
|
|
|
|
|
|
|
| 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",
|
|
|
|
| 10 |
"prompt": prompt,
|
| 11 |
"num_images": 1,
|
| 12 |
}
|
| 13 |
+
response = requests.post(request_url, headers=headers, json=data)
|
| 14 |
response_json = response.json()
|
| 15 |
|
| 16 |
+
# Get the URL of the first generated image
|
| 17 |
image_url = response_json["data"][0]["url"]
|
| 18 |
|
| 19 |
return image_url
|
| 20 |
+
|
| 21 |
css = """
|
| 22 |
footer {visibility: hidden !important;}
|
| 23 |
"""
|
| 24 |
+
|
| 25 |
+
# Create the interface using Gradio
|
| 26 |
with gr.Blocks(css=css, theme='YTheme/Sketch') as demo:
|
| 27 |
with gr.Row():
|
| 28 |
+
gr.Markdown("## Image Generation Tool")
|
| 29 |
+
gr.Markdown("Enter the required information below to generate an image.")
|
| 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 |
with gr.Row():
|
| 34 |
+
prompt_input = gr.Textbox(label="Image Description")
|
| 35 |
+
submit_btn = gr.Button("Generate Image", variant='primary')
|
| 36 |
+
image_output = gr.Image(label="Generated Image")
|
| 37 |
|
| 38 |
+
submit_btn.click(fn=generate_image, inputs=[prompt_input, api_key_input, request_url_input], outputs=image_output)
|
| 39 |
|
| 40 |
+
demo.launch()
|