Spaces:
Paused
Paused
commit
Browse files
app.py
CHANGED
|
@@ -38,7 +38,10 @@ from refiners.foundationals.latent_diffusion.stable_diffusion_1.multi_upscaler i
|
|
| 38 |
MultiUpscaler,
|
| 39 |
UpscalerCheckpoints,
|
| 40 |
)
|
|
|
|
| 41 |
|
|
|
|
|
|
|
| 42 |
|
| 43 |
Tile = tuple[int, int, Image.Image]
|
| 44 |
Tiles = list[tuple[int, int, list[Tile]]]
|
|
@@ -500,7 +503,7 @@ function custom(){
|
|
| 500 |
# torch pipes
|
| 501 |
|
| 502 |
image_pipe = FluxPipeline.from_pretrained(base, torch_dtype=torch.bfloat16).to(device)
|
| 503 |
-
image_pipe.enable_model_cpu_offload()
|
| 504 |
|
| 505 |
# functionality
|
| 506 |
|
|
@@ -509,7 +512,7 @@ def upscaler(
|
|
| 509 |
input_image: Image.Image,
|
| 510 |
prompt: str = "masterpiece, best quality, highres",
|
| 511 |
negative_prompt: str = "worst quality, low quality, normal quality",
|
| 512 |
-
seed: int =
|
| 513 |
upscale_factor: int = 8,
|
| 514 |
controlnet_scale: float = 0.6,
|
| 515 |
controlnet_decay: float = 1.0,
|
|
@@ -520,10 +523,15 @@ def upscaler(
|
|
| 520 |
num_inference_steps: int = 18,
|
| 521 |
solver: str = "DDIM",
|
| 522 |
) -> Image.Image:
|
|
|
|
|
|
|
|
|
|
| 523 |
manual_seed(seed)
|
| 524 |
|
| 525 |
solver_type: type[Solver] = getattr(solvers, solver)
|
| 526 |
|
|
|
|
|
|
|
| 527 |
enhanced_image = enhancer.upscale(
|
| 528 |
image=input_image,
|
| 529 |
prompt=prompt,
|
|
@@ -539,6 +547,8 @@ def upscaler(
|
|
| 539 |
solver_type=solver_type,
|
| 540 |
)
|
| 541 |
|
|
|
|
|
|
|
| 542 |
return enhanced_image
|
| 543 |
|
| 544 |
@spaces.GPU(duration=180)
|
|
@@ -547,12 +557,15 @@ def summarize_text(
|
|
| 547 |
pegasus_tokenizer = PegasusTokenizerFast.from_pretrained("google/pegasus-xsum"),
|
| 548 |
pegasus_model = PegasusForConditionalGeneration.from_pretrained("google/pegasus-xsum")
|
| 549 |
):
|
| 550 |
-
|
|
|
|
| 551 |
pegasus_tokenizer(text,return_tensors="pt").input_ids,
|
| 552 |
max_length=max_length,
|
| 553 |
num_beams=num_beams,
|
| 554 |
early_stopping=early_stopping
|
| 555 |
)[0], skip_special_tokens=True)
|
|
|
|
|
|
|
| 556 |
|
| 557 |
def generate_random_string(length):
|
| 558 |
characters = str(ascii_letters + digits)
|
|
@@ -560,7 +573,8 @@ def generate_random_string(length):
|
|
| 560 |
|
| 561 |
@spaces.GPU(duration=180)
|
| 562 |
def pipe_generate(p1,p2):
|
| 563 |
-
|
|
|
|
| 564 |
prompt=p1,
|
| 565 |
negative_prompt=p2,
|
| 566 |
height=height,
|
|
@@ -571,9 +585,13 @@ def pipe_generate(p1,p2):
|
|
| 571 |
max_sequence_length=seq,
|
| 572 |
generator=torch.Generator(device).manual_seed(int(str(random.random()).split(".")[1]))
|
| 573 |
).images[0]
|
|
|
|
|
|
|
| 574 |
|
| 575 |
def handle_generate(artist,song,genre,lyrics):
|
| 576 |
|
|
|
|
|
|
|
| 577 |
pos_artist = re.sub("([ \t\n]){1,}", " ", artist).strip()
|
| 578 |
pos_song = re.sub("([ \t\n]){1,}", " ", song).strip()
|
| 579 |
pos_song = ' '.join(word[0].upper() + word[1:] for word in pos_song.split())
|
|
|
|
| 38 |
MultiUpscaler,
|
| 39 |
UpscalerCheckpoints,
|
| 40 |
)
|
| 41 |
+
from datetime import datetime
|
| 42 |
|
| 43 |
+
def log(msg):
|
| 44 |
+
print(f'{datetime.now().time()} {msg}')
|
| 45 |
|
| 46 |
Tile = tuple[int, int, Image.Image]
|
| 47 |
Tiles = list[tuple[int, int, list[Tile]]]
|
|
|
|
| 503 |
# torch pipes
|
| 504 |
|
| 505 |
image_pipe = FluxPipeline.from_pretrained(base, torch_dtype=torch.bfloat16).to(device)
|
| 506 |
+
#image_pipe.enable_model_cpu_offload()
|
| 507 |
|
| 508 |
# functionality
|
| 509 |
|
|
|
|
| 512 |
input_image: Image.Image,
|
| 513 |
prompt: str = "masterpiece, best quality, highres",
|
| 514 |
negative_prompt: str = "worst quality, low quality, normal quality",
|
| 515 |
+
seed: int = int(str(random.random()).split(".")[1]),
|
| 516 |
upscale_factor: int = 8,
|
| 517 |
controlnet_scale: float = 0.6,
|
| 518 |
controlnet_decay: float = 1.0,
|
|
|
|
| 523 |
num_inference_steps: int = 18,
|
| 524 |
solver: str = "DDIM",
|
| 525 |
) -> Image.Image:
|
| 526 |
+
|
| 527 |
+
log(f'CALL upscaler')
|
| 528 |
+
|
| 529 |
manual_seed(seed)
|
| 530 |
|
| 531 |
solver_type: type[Solver] = getattr(solvers, solver)
|
| 532 |
|
| 533 |
+
log(f'DBG upscaler 1')
|
| 534 |
+
|
| 535 |
enhanced_image = enhancer.upscale(
|
| 536 |
image=input_image,
|
| 537 |
prompt=prompt,
|
|
|
|
| 547 |
solver_type=solver_type,
|
| 548 |
)
|
| 549 |
|
| 550 |
+
log(f'RET upscaler')
|
| 551 |
+
|
| 552 |
return enhanced_image
|
| 553 |
|
| 554 |
@spaces.GPU(duration=180)
|
|
|
|
| 557 |
pegasus_tokenizer = PegasusTokenizerFast.from_pretrained("google/pegasus-xsum"),
|
| 558 |
pegasus_model = PegasusForConditionalGeneration.from_pretrained("google/pegasus-xsum")
|
| 559 |
):
|
| 560 |
+
log(f'CALL summarize_text')
|
| 561 |
+
summary = pegasus_tokenizer.decode( pegasus_model.generate(
|
| 562 |
pegasus_tokenizer(text,return_tensors="pt").input_ids,
|
| 563 |
max_length=max_length,
|
| 564 |
num_beams=num_beams,
|
| 565 |
early_stopping=early_stopping
|
| 566 |
)[0], skip_special_tokens=True)
|
| 567 |
+
log(f'RET summarize_text with summary as {summary}')
|
| 568 |
+
return summary
|
| 569 |
|
| 570 |
def generate_random_string(length):
|
| 571 |
characters = str(ascii_letters + digits)
|
|
|
|
| 573 |
|
| 574 |
@spaces.GPU(duration=180)
|
| 575 |
def pipe_generate(p1,p2):
|
| 576 |
+
log(f'CALL pipe_generate')
|
| 577 |
+
img = image_pipe(
|
| 578 |
prompt=p1,
|
| 579 |
negative_prompt=p2,
|
| 580 |
height=height,
|
|
|
|
| 585 |
max_sequence_length=seq,
|
| 586 |
generator=torch.Generator(device).manual_seed(int(str(random.random()).split(".")[1]))
|
| 587 |
).images[0]
|
| 588 |
+
log(f'RET pipe_generate')
|
| 589 |
+
return img
|
| 590 |
|
| 591 |
def handle_generate(artist,song,genre,lyrics):
|
| 592 |
|
| 593 |
+
log(f'CALL handle_generate')
|
| 594 |
+
|
| 595 |
pos_artist = re.sub("([ \t\n]){1,}", " ", artist).strip()
|
| 596 |
pos_song = re.sub("([ \t\n]){1,}", " ", song).strip()
|
| 597 |
pos_song = ' '.join(word[0].upper() + word[1:] for word in pos_song.split())
|