Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,10 @@ import random
|
|
9 |
import os
|
10 |
from huggingface_hub import InferenceClient
|
11 |
from fpdf import FPDF
|
|
|
|
|
|
|
|
|
12 |
|
13 |
def setup_session():
|
14 |
try:
|
@@ -494,6 +498,50 @@ def update_prompts_and_description(category, style):
|
|
494 |
style_description = get_style_description(style)
|
495 |
return style_description
|
496 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
497 |
|
498 |
def generate_images(blog_post):
|
499 |
images = []
|
@@ -595,8 +643,8 @@ with gr.Blocks() as demo:
|
|
595 |
fn=generate_images,
|
596 |
inputs=[output],
|
597 |
outputs=image_outputs
|
598 |
-
)
|
599 |
-
|
600 |
save_pdf_btn = gr.Button("PDF๋ก ์ ์ฅํ๊ธฐ")
|
601 |
pdf_output = gr.File(label="์์ฑ๋ PDF ํ์ผ")
|
602 |
|
@@ -605,4 +653,4 @@ with gr.Blocks() as demo:
|
|
605 |
category.change(fn=update_prompts_and_description, inputs=[category, style], outputs=[style_description])
|
606 |
style.change(fn=update_prompts_and_description, inputs=[category, style], outputs=[style_description])
|
607 |
|
608 |
-
demo.launch()
|
|
|
9 |
import os
|
10 |
from huggingface_hub import InferenceClient
|
11 |
from fpdf import FPDF
|
12 |
+
from transformers import pipeline
|
13 |
+
import torch
|
14 |
+
from diffusers import StableDiffusionXLPipeline
|
15 |
+
import uuid
|
16 |
|
17 |
def setup_session():
|
18 |
try:
|
|
|
498 |
style_description = get_style_description(style)
|
499 |
return style_description
|
500 |
|
501 |
+
# ์ด๋ฏธ์ง ์์ฑ์ ์ํ ์ค์
|
502 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
503 |
+
|
504 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
505 |
+
|
506 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
507 |
+
"SG161222/RealVisXL_V4.0",
|
508 |
+
torch_dtype=torch.float16,
|
509 |
+
use_safetensors=True,
|
510 |
+
add_watermarker=False,
|
511 |
+
variant="fp16"
|
512 |
+
).to(device)
|
513 |
+
|
514 |
+
def generate_image(prompt: str):
|
515 |
+
# ํ๊ธ ์
๋ ฅ ๊ฐ์ง ๋ฐ ๋ฒ์ญ
|
516 |
+
if any('\uac00' <= char <= '\ud7a3' for char in prompt):
|
517 |
+
translated = translator(prompt, max_length=512)
|
518 |
+
prompt = translated[0]['translation_text']
|
519 |
+
|
520 |
+
# Hi-res์ 3840x2160 ์คํ์ผ ์ ์ฉ
|
521 |
+
prompt = f"hyper-realistic 8K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic"
|
522 |
+
|
523 |
+
# ๊ณ ์ ๋ ์ค์ ๊ฐ
|
524 |
+
negative_prompt = "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly, (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers:1.4), disconnected limbs, mutation, mutated, disgusting, amputation"
|
525 |
+
width = 1024
|
526 |
+
height = 1024
|
527 |
+
guidance_scale = 6
|
528 |
+
num_inference_steps = 100
|
529 |
+
seed = random.randint(0, 2**32 - 1)
|
530 |
+
generator = torch.Generator().manual_seed(seed)
|
531 |
+
|
532 |
+
image = pipe(
|
533 |
+
prompt=prompt,
|
534 |
+
negative_prompt=negative_prompt,
|
535 |
+
width=width,
|
536 |
+
height=height,
|
537 |
+
guidance_scale=guidance_scale,
|
538 |
+
num_inference_steps=num_inference_steps,
|
539 |
+
generator=generator,
|
540 |
+
).images[0]
|
541 |
+
|
542 |
+
unique_name = str(uuid.uuid4()) + ".png"
|
543 |
+
image.save(unique_name)
|
544 |
+
return unique_name
|
545 |
|
546 |
def generate_images(blog_post):
|
547 |
images = []
|
|
|
643 |
fn=generate_images,
|
644 |
inputs=[output],
|
645 |
outputs=image_outputs
|
646 |
+
)
|
647 |
+
|
648 |
save_pdf_btn = gr.Button("PDF๋ก ์ ์ฅํ๊ธฐ")
|
649 |
pdf_output = gr.File(label="์์ฑ๋ PDF ํ์ผ")
|
650 |
|
|
|
653 |
category.change(fn=update_prompts_and_description, inputs=[category, style], outputs=[style_description])
|
654 |
style.change(fn=update_prompts_and_description, inputs=[category, style], outputs=[style_description])
|
655 |
|
656 |
+
demo.launch()
|