Spaces:
Paused
Paused
Commit ·
c3a9fae
1
Parent(s): 70c6d65
Remove unused environment variable and enhance random number generator initialization; delete obsolete prompt enhancement function and related UI elements
Browse files
app.py
CHANGED
|
@@ -29,10 +29,8 @@ import gradio as gr
|
|
| 29 |
from models.infinity import Infinity
|
| 30 |
from models.basic import *
|
| 31 |
from utils.dynamic_resolution import dynamic_resolution_h_w, h_div_w_templates
|
| 32 |
-
from gradio_client import Client
|
| 33 |
|
| 34 |
torch._dynamo.config.cache_size_limit = 64
|
| 35 |
-
client = Client("Qwen/Qwen2.5-72B-Instruct")
|
| 36 |
|
| 37 |
# Define a function to download weights if not present
|
| 38 |
def download_infinity_weights(weights_path):
|
|
@@ -378,60 +376,6 @@ def load_transformer(vae, args):
|
|
| 378 |
)
|
| 379 |
return infinity
|
| 380 |
|
| 381 |
-
def enhance_prompt(prompt):
|
| 382 |
-
SYSTEM = """You are part of a team of bots that creates images. You work with an assistant bot that will draw anything you say.
|
| 383 |
-
|
| 384 |
-
When given a user prompt, your role is to transform it into a creative, detailed, and vivid image description that focuses on visual and sensory features. Avoid directly referencing specific real-world people, places, or cultural knowledge unless explicitly requested by the user.
|
| 385 |
-
|
| 386 |
-
### Guidelines for Generating the Output:
|
| 387 |
-
|
| 388 |
-
1. **Output Format:**
|
| 389 |
-
Your response must be in the following dictionary format:
|
| 390 |
-
```json
|
| 391 |
-
{
|
| 392 |
-
"prompt": "<enhanced image description>",
|
| 393 |
-
"cfg": <cfg value>
|
| 394 |
-
}
|
| 395 |
-
```
|
| 396 |
-
|
| 397 |
-
2. **Enhancing the "prompt" field:**
|
| 398 |
-
- Use your creativity to expand short or vague prompts into highly detailed, visually rich descriptions.
|
| 399 |
-
- Focus on describing visual and sensory elements, such as colors, textures, shapes, lighting, and emotions.
|
| 400 |
-
- Avoid including known real-world information unless the user explicitly requests it. Instead, describe features that evoke the essence or appearance of the scene or subject.
|
| 401 |
-
- For particularly long user prompts (over 50 words), output them directly without refinement.
|
| 402 |
-
- Image descriptions must remain between 8-512 words. Any excess text will be ignored.
|
| 403 |
-
- If the user's request involves rendering specific text in the image, enclose that text in single quotation marks and prefix it with "the text".
|
| 404 |
-
|
| 405 |
-
3. **Determining the "cfg" field:**
|
| 406 |
-
- If the image to be generated is likely to feature a clear face, set `"cfg": 1`.
|
| 407 |
-
- If the image does not prominently feature a face, set `"cfg": 3`.
|
| 408 |
-
|
| 409 |
-
4. **Examples of Enhanced Prompts:**
|
| 410 |
-
- **User prompt:** "a tree"
|
| 411 |
-
**Enhanced prompt:** "A towering tree with a textured bark of intricate ridges and grooves stands under a pale blue sky. Its sprawling branches create an umbrella of rich, deep green foliage, with a few golden leaves scattered, catching the sunlight like tiny stars."
|
| 412 |
-
**Cfg:** `3`
|
| 413 |
-
|
| 414 |
-
- **User prompt:** "a person reading"
|
| 415 |
-
**Enhanced prompt:** "A figure sits on a cozy armchair, illuminated by the soft, warm glow of a nearby lamp. Their posture is relaxed, and their hands gently hold an open book. Shadows dance across their thoughtful expression, while the fabric of their clothing appears textured and soft, with subtle folds."
|
| 416 |
-
**Cfg:** `1`
|
| 417 |
-
|
| 418 |
-
5. **Your Output:**
|
| 419 |
-
Always return a single dictionary containing both `"prompt"` and `"cfg"` fields. Avoid any additional commentary or explanations.
|
| 420 |
-
|
| 421 |
-
Don't write anything except the dictionary in the output. (Don't start with ```)
|
| 422 |
-
"""
|
| 423 |
-
result = client.predict(
|
| 424 |
-
query=prompt,
|
| 425 |
-
history=[],
|
| 426 |
-
system=SYSTEM,
|
| 427 |
-
api_name="/model_chat"
|
| 428 |
-
)
|
| 429 |
-
|
| 430 |
-
dict_of_inputs = json.loads(result[1][-1][-1])
|
| 431 |
-
print(dict_of_inputs)
|
| 432 |
-
|
| 433 |
-
return gr.update(value=dict_of_inputs["prompt"]), gr.update(value=float(dict_of_inputs['cfg']))
|
| 434 |
-
|
| 435 |
# Set up paths
|
| 436 |
weights_path = Path(__file__).parent / 'weights'
|
| 437 |
weights_path.mkdir(exist_ok=True)
|
|
@@ -554,7 +498,6 @@ with gr.Blocks() as demo:
|
|
| 554 |
# Prompt Settings
|
| 555 |
gr.Markdown("### Prompt Settings")
|
| 556 |
prompt = gr.Textbox(label="Prompt", value="alien spaceship enterprise", placeholder="Enter your prompt here...")
|
| 557 |
-
enhance_prompt_button = gr.Button("Enhance Prompt", variant="secondary")
|
| 558 |
|
| 559 |
# Image Settings
|
| 560 |
gr.Markdown("### Image Settings")
|
|
@@ -575,13 +518,6 @@ with gr.Blocks() as demo:
|
|
| 575 |
|
| 576 |
# Error Handling
|
| 577 |
error_message = gr.Textbox(label="Error Message", visible=False)
|
| 578 |
-
|
| 579 |
-
# Link the enhance prompt button to the prompt enhancement function
|
| 580 |
-
enhance_prompt_button.click(
|
| 581 |
-
enhance_prompt,
|
| 582 |
-
inputs=prompt,
|
| 583 |
-
outputs=[prompt, cfg],
|
| 584 |
-
)
|
| 585 |
|
| 586 |
# Link the generate button to the image generation function
|
| 587 |
generate_button.click(
|
|
|
|
| 29 |
from models.infinity import Infinity
|
| 30 |
from models.basic import *
|
| 31 |
from utils.dynamic_resolution import dynamic_resolution_h_w, h_div_w_templates
|
|
|
|
| 32 |
|
| 33 |
torch._dynamo.config.cache_size_limit = 64
|
|
|
|
| 34 |
|
| 35 |
# Define a function to download weights if not present
|
| 36 |
def download_infinity_weights(weights_path):
|
|
|
|
| 376 |
)
|
| 377 |
return infinity
|
| 378 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
# Set up paths
|
| 380 |
weights_path = Path(__file__).parent / 'weights'
|
| 381 |
weights_path.mkdir(exist_ok=True)
|
|
|
|
| 498 |
# Prompt Settings
|
| 499 |
gr.Markdown("### Prompt Settings")
|
| 500 |
prompt = gr.Textbox(label="Prompt", value="alien spaceship enterprise", placeholder="Enter your prompt here...")
|
|
|
|
| 501 |
|
| 502 |
# Image Settings
|
| 503 |
gr.Markdown("### Image Settings")
|
|
|
|
| 518 |
|
| 519 |
# Error Handling
|
| 520 |
error_message = gr.Textbox(label="Error Message", visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 521 |
|
| 522 |
# Link the generate button to the image generation function
|
| 523 |
generate_button.click(
|