Spaces:
Running
on
Zero
Running
on
Zero
positive_magic [en, zh] (#3)
Browse files- positive_magic [en, zh] (87337ae4c5527b3ac556876f65f0b727452bd9b6)
app.py
CHANGED
|
@@ -9,6 +9,7 @@ from typing import Union, List, Optional
|
|
| 9 |
import numpy as np
|
| 10 |
import time
|
| 11 |
import zipfile
|
|
|
|
| 12 |
|
| 13 |
# Description for the app
|
| 14 |
DESCRIPTION = """## Qwen Image Hpc/."""
|
|
@@ -60,6 +61,16 @@ def get_duration(
|
|
| 60 |
per_image_duration = 5 + num_inference_steps * step_duration
|
| 61 |
return 10 + num_images * per_image_duration
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# Generation function for Qwen/Qwen-Image
|
| 64 |
def generate_qwen(
|
| 65 |
prompt: str,
|
|
@@ -122,9 +133,15 @@ def generate(
|
|
| 122 |
zip_images: bool,
|
| 123 |
progress=gr.Progress(track_tqdm=True),
|
| 124 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
final_negative_prompt = negative_prompt if use_negative_prompt else ""
|
| 126 |
return generate_qwen(
|
| 127 |
-
prompt=
|
| 128 |
negative_prompt=final_negative_prompt,
|
| 129 |
seed=seed,
|
| 130 |
width=width,
|
|
|
|
| 9 |
import numpy as np
|
| 10 |
import time
|
| 11 |
import zipfile
|
| 12 |
+
import re
|
| 13 |
|
| 14 |
# Description for the app
|
| 15 |
DESCRIPTION = """## Qwen Image Hpc/."""
|
|
|
|
| 61 |
per_image_duration = 5 + num_inference_steps * step_duration
|
| 62 |
return 10 + num_images * per_image_duration
|
| 63 |
|
| 64 |
+
# Positive Magic texts
|
| 65 |
+
positive_magic = {
|
| 66 |
+
"en": "Ultra HD, 4K, cinematic composition.",
|
| 67 |
+
"zh": "超清,4K,电影级构图"
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
# Function to check if the prompt contains Chinese characters
|
| 71 |
+
def contains_chinese(text):
|
| 72 |
+
return bool(re.search(r'[\u4e00-\u9fff]', text))
|
| 73 |
+
|
| 74 |
# Generation function for Qwen/Qwen-Image
|
| 75 |
def generate_qwen(
|
| 76 |
prompt: str,
|
|
|
|
| 133 |
zip_images: bool,
|
| 134 |
progress=gr.Progress(track_tqdm=True),
|
| 135 |
):
|
| 136 |
+
# Enhance the prompt with Positive Magic based on language
|
| 137 |
+
if contains_chinese(prompt):
|
| 138 |
+
final_prompt = prompt + " " + positive_magic["zh"]
|
| 139 |
+
else:
|
| 140 |
+
final_prompt = prompt + " " + positive_magic["en"]
|
| 141 |
+
|
| 142 |
final_negative_prompt = negative_prompt if use_negative_prompt else ""
|
| 143 |
return generate_qwen(
|
| 144 |
+
prompt=final_prompt,
|
| 145 |
negative_prompt=final_negative_prompt,
|
| 146 |
seed=seed,
|
| 147 |
width=width,
|