Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import random
|
|
| 6 |
import os
|
| 7 |
from PIL import Image
|
| 8 |
from deep_translator import GoogleTranslator
|
| 9 |
-
from gradio_client import Client
|
| 10 |
|
| 11 |
# os.makedirs('assets', exist_ok=True)
|
| 12 |
if not os.path.exists('icon.jpg'):
|
|
@@ -16,19 +16,15 @@ API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-
|
|
| 16 |
timeout = 100
|
| 17 |
|
| 18 |
def enhance_prompt(prompt):
|
| 19 |
-
|
| 20 |
-
client = Client("K00B404/mistral-nemo-prompt-enhancer")
|
| 21 |
result = client.predict(
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
temperature=0.7,
|
| 26 |
-
top_p=0.95,
|
| 27 |
-
api_name="/chat"
|
| 28 |
)
|
| 29 |
return result
|
| 30 |
|
| 31 |
-
def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, huggingface_api_key=None, use_dev=False):
|
| 32 |
# Determine which API URL to use
|
| 33 |
api_url = API_URL_DEV if use_dev else API_URL
|
| 34 |
|
|
@@ -53,11 +49,11 @@ def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Ka
|
|
| 53 |
prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
|
| 54 |
print(f'\033[1mGeneration {key} translation:\033[0m {prompt}')
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
| 60 |
-
prompt = f"{
|
| 61 |
print(f'\033[1mGeneration {key}:\033[0m {prompt}')
|
| 62 |
|
| 63 |
# If seed is -1, generate a random seed and use it
|
|
@@ -142,6 +138,7 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as app:
|
|
| 142 |
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
| 143 |
huggingface_api_key = gr.Textbox(label="Hugging Face API Key (required for API calls)", placeholder="Enter your Hugging Face API Key here", type="password", elem_id="api-key")
|
| 144 |
use_dev = gr.Checkbox(label="Use Dev API", value=False, elem_id="use-dev-checkbox")
|
|
|
|
| 145 |
|
| 146 |
with gr.Row():
|
| 147 |
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
|
@@ -149,7 +146,7 @@ with gr.Blocks(theme='Nymbo/Nymbo_Theme', css=css) as app:
|
|
| 149 |
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
| 150 |
seed_output = gr.Textbox(label="Seed Used", elem_id="seed-output")
|
| 151 |
|
| 152 |
-
# Adjust the click function to include the API key and
|
| 153 |
-
text_button.click(query, inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength, huggingface_api_key, use_dev], outputs=[image_output, seed_output])
|
| 154 |
|
| 155 |
app.launch(show_api=True, share=False,show_error=True)
|
|
|
|
| 6 |
import os
|
| 7 |
from PIL import Image
|
| 8 |
from deep_translator import GoogleTranslator
|
| 9 |
+
from gradio_client import Client
|
| 10 |
|
| 11 |
# os.makedirs('assets', exist_ok=True)
|
| 12 |
if not os.path.exists('icon.jpg'):
|
|
|
|
| 16 |
timeout = 100
|
| 17 |
|
| 18 |
def enhance_prompt(prompt):
|
| 19 |
+
client = Client("K00B404/Mistral-Nemo-custom")
|
|
|
|
| 20 |
result = client.predict(
|
| 21 |
+
system_prompt="You are a image generation prompt enhancer and must respond only with the enhanced version of the users input prompt",
|
| 22 |
+
user_message=f"###input image generation prompt### {prompt}",
|
| 23 |
+
api_name="/predict"
|
|
|
|
|
|
|
|
|
|
| 24 |
)
|
| 25 |
return result
|
| 26 |
|
| 27 |
+
def query(prompt, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, huggingface_api_key=None, use_dev=False, enhance_prompt_option=False):
|
| 28 |
# Determine which API URL to use
|
| 29 |
api_url = API_URL_DEV if use_dev else API_URL
|
| 30 |
|
|
|
|
| 49 |
prompt = GoogleTranslator(source='ru', target='en').translate(prompt)
|
| 50 |
print(f'\033[1mGeneration {key} translation:\033[0m {prompt}')
|
| 51 |
|
| 52 |
+
if enhance_prompt_option:
|
| 53 |
+
prompt = enhance_prompt(prompt)
|
| 54 |
+
print(f'\033[1mGeneration {key} enhanced prompt:\033[0m {prompt}')
|
| 55 |
|
| 56 |
+
prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
|
| 57 |
print(f'\033[1mGeneration {key}:\033[0m {prompt}')
|
| 58 |
|
| 59 |
# If seed is -1, generate a random seed and use it
|
|
|
|
| 138 |
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
| 139 |
huggingface_api_key = gr.Textbox(label="Hugging Face API Key (required for API calls)", placeholder="Enter your Hugging Face API Key here", type="password", elem_id="api-key")
|
| 140 |
use_dev = gr.Checkbox(label="Use Dev API", value=False, elem_id="use-dev-checkbox")
|
| 141 |
+
enhance_prompt_option = gr.Checkbox(label="Enhance Prompt", value=False, elem_id="enhance-prompt-checkbox")
|
| 142 |
|
| 143 |
with gr.Row():
|
| 144 |
text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
|
|
|
|
| 146 |
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
|
| 147 |
seed_output = gr.Textbox(label="Seed Used", elem_id="seed-output")
|
| 148 |
|
| 149 |
+
# Adjust the click function to include the API key, use_dev, and enhance_prompt_option as inputs
|
| 150 |
+
text_button.click(query, inputs=[text_prompt, negative_prompt, steps, cfg, method, seed, strength, huggingface_api_key, use_dev, enhance_prompt_option], outputs=[image_output, seed_output])
|
| 151 |
|
| 152 |
app.launch(show_api=True, share=False,show_error=True)
|