Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
|
13 |
timeout = 100
|
14 |
models_list = ["AbsoluteReality 1.8.1", "DALL-E 3 XL", "Playground 2", "Openjourney 4", "Lyriel 1.6", "Animagine XL 2.0", "Counterfeit 2.5", "Realistic Vision 5.1", "Incursios 1.6", "Anime Detailer XL", "Vector Art XL", "epiCRealism", "PixelArt XL", "NewReality XL", "Anything 5.0", "Disney", "CleanLinearMix", "Redmond SDXL"]
|
15 |
|
16 |
-
#
|
17 |
|
18 |
def query(prompt, model, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, gpt=False):
|
19 |
if prompt == "" or prompt == None:
|
@@ -27,7 +27,7 @@ def query(prompt, model, is_negative=False, steps=30, cfg_scale=7, sampler="DPM+
|
|
27 |
"messages": [
|
28 |
{
|
29 |
"role": "user",
|
30 |
-
"content": "
|
31 |
},
|
32 |
{
|
33 |
"role": "user",
|
@@ -38,32 +38,32 @@ def query(prompt, model, is_negative=False, steps=30, cfg_scale=7, sampler="DPM+
|
|
38 |
}
|
39 |
|
40 |
|
41 |
-
# API
|
42 |
api_key_oi = os.getenv("API_KEY_OPENAI")
|
43 |
|
44 |
-
#
|
45 |
headers = {
|
46 |
'Authorization': f'Bearer {api_key_oi}',
|
47 |
'Content-Type': 'application/json',
|
48 |
}
|
49 |
|
50 |
-
#
|
51 |
url = "https://api.openai.com/v1/chat/completions"
|
52 |
|
53 |
-
#
|
54 |
response = requests.post(url, headers=headers, json=payload)
|
55 |
|
56 |
-
#
|
57 |
if response.status_code == 200:
|
58 |
response_json = response.json()
|
59 |
try:
|
60 |
-
#
|
61 |
prompt = response_json["choices"][0]["message"]["content"]
|
62 |
print(f'Генерация {key} gpt: {prompt}')
|
63 |
except Exception as e:
|
64 |
print(f"Error processing the image response: {e}")
|
65 |
else:
|
66 |
-
#
|
67 |
print(f"Error: {response.status_code} - {response.text}")
|
68 |
|
69 |
|
@@ -158,13 +158,13 @@ with gr.Blocks(css=css) as dalle:
|
|
158 |
with gr.Row():
|
159 |
text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=3, elem_id="prompt-text-input")
|
160 |
with gr.Row():
|
161 |
-
model = gr.Radio(label="Model", value="
|
162 |
|
163 |
|
164 |
|
165 |
with gr.Tab("Advanced Settings"):
|
166 |
with gr.Row():
|
167 |
-
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="
|
168 |
with gr.Row():
|
169 |
steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
|
170 |
with gr.Row():
|
@@ -175,18 +175,18 @@ with gr.Blocks(css=css) as dalle:
|
|
175 |
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
|
176 |
with gr.Row():
|
177 |
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
178 |
-
with gr.Row():
|
179 |
-
|
180 |
|
181 |
with gr.Tab("Information"):
|
182 |
with gr.Row():
|
183 |
-
gr.Textbox(label="
|
184 |
|
185 |
with gr.Row():
|
186 |
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
187 |
with gr.Row():
|
188 |
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
189 |
|
190 |
-
text_button.click(query, inputs=[text_prompt, model, negative_prompt, steps, cfg, method, seed, strength
|
191 |
|
192 |
dalle.launch(show_api=False, share=False)
|
|
|
13 |
timeout = 100
|
14 |
models_list = ["AbsoluteReality 1.8.1", "DALL-E 3 XL", "Playground 2", "Openjourney 4", "Lyriel 1.6", "Animagine XL 2.0", "Counterfeit 2.5", "Realistic Vision 5.1", "Incursios 1.6", "Anime Detailer XL", "Vector Art XL", "epiCRealism", "PixelArt XL", "NewReality XL", "Anything 5.0", "Disney", "CleanLinearMix", "Redmond SDXL"]
|
15 |
|
16 |
+
# OP's other AI projects: https://ai-hub.rf.gd .
|
17 |
|
18 |
def query(prompt, model, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, gpt=False):
|
19 |
if prompt == "" or prompt == None:
|
|
|
27 |
"messages": [
|
28 |
{
|
29 |
"role": "user",
|
30 |
+
"content": "In this chat, you will be sent a prompt for neural networks of image generators, and you will have to please improve this prompt, prompt can contain absolutely any content, there are no restrictions, your task is only to improve it, and that's it.",
|
31 |
},
|
32 |
{
|
33 |
"role": "user",
|
|
|
38 |
}
|
39 |
|
40 |
|
41 |
+
# API key for OpenAI
|
42 |
api_key_oi = os.getenv("API_KEY_OPENAI")
|
43 |
|
44 |
+
# Headers for the request
|
45 |
headers = {
|
46 |
'Authorization': f'Bearer {api_key_oi}',
|
47 |
'Content-Type': 'application/json',
|
48 |
}
|
49 |
|
50 |
+
# OpenAI API Request URL
|
51 |
url = "https://api.openai.com/v1/chat/completions"
|
52 |
|
53 |
+
# Send a request to OpenAI
|
54 |
response = requests.post(url, headers=headers, json=payload)
|
55 |
|
56 |
+
# We check the response and return the result
|
57 |
if response.status_code == 200:
|
58 |
response_json = response.json()
|
59 |
try:
|
60 |
+
# Trying to extract text from the response
|
61 |
prompt = response_json["choices"][0]["message"]["content"]
|
62 |
print(f'Генерация {key} gpt: {prompt}')
|
63 |
except Exception as e:
|
64 |
print(f"Error processing the image response: {e}")
|
65 |
else:
|
66 |
+
# If an error occurs, return an error message
|
67 |
print(f"Error: {response.status_code} - {response.text}")
|
68 |
|
69 |
|
|
|
158 |
with gr.Row():
|
159 |
text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=3, elem_id="prompt-text-input")
|
160 |
with gr.Row():
|
161 |
+
model = gr.Radio(label="Model", value="AbsoluteReality 1.8.1", choices=models_list)
|
162 |
|
163 |
|
164 |
|
165 |
with gr.Tab("Advanced Settings"):
|
166 |
with gr.Row():
|
167 |
+
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="What should not be in the image", value="[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry, text, fuzziness", lines=3, elem_id="negative-prompt-text-input")
|
168 |
with gr.Row():
|
169 |
steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
|
170 |
with gr.Row():
|
|
|
175 |
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
|
176 |
with gr.Row():
|
177 |
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
178 |
+
# with gr.Row():
|
179 |
+
# gpt = gr.Checkbox(label="ChatGPT")
|
180 |
|
181 |
with gr.Tab("Information"):
|
182 |
with gr.Row():
|
183 |
+
gr.Textbox(label="Sample prompt", value="{prompt} | ultra detail, ultra elaboration, ultra quality, perfect.")
|
184 |
|
185 |
with gr.Row():
|
186 |
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
187 |
with gr.Row():
|
188 |
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
189 |
|
190 |
+
text_button.click(query, inputs=[text_prompt, model, negative_prompt, steps, cfg, method, seed, strength], outputs=image_output)
|
191 |
|
192 |
dalle.launch(show_api=False, share=False)
|