File size: 3,608 Bytes
a3c8eab
 
 
 
 
 
 
 
 
 
 
e0887f1
a3c8eab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b0e3c1
a3c8eab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ebed1c6
 
 
 
 
 
a3c8eab
ebed1c6
a3c8eab
 
ebed1c6
 
 
 
 
a3c8eab
 
ebed1c6
 
a3c8eab
 
ebed1c6
 
a3c8eab
 
 
 
 
 
 
 
ebed1c6
 
 
 
 
03da6cb
 
ebed1c6
 
03da6cb
 
ebed1c6
 
 
a3c8eab
 
 
 
ebed1c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import os
import gc
import gradio as gr
import numpy as np
import torch
import json
import spaces
import random
import config
import utils
import logging
import prompt_generator
from PIL import Image, PngImagePlugin
from datetime import datetime
from diffusers.models import AutoencoderKL
from diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipeline
from config import (
    MODEL,
    MIN_IMAGE_SIZE,
    MAX_IMAGE_SIZE,
    USE_TORCH_COMPILE,
    ENABLE_CPU_OFFLOAD,
    OUTPUT_DIR,
    DEFAULT_NEGATIVE_PROMPT,
    DEFAULT_ASPECT_RATIO,
    sampler_list,
    aspect_ratios,
    style_list,
    # 設定
    TEXT_TO_PROMPT_ENABLED,
    DEFAULT_CATEGORY,
    DEFAULT_SERIES,
    DEFAULT_CHARACTER,
    series_list,
    character_list,
    category_list,
)
import time
from typing import List, Dict, Tuple, Optional

# Enhanced logging configuration
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S'
)
logger = logging.getLogger(__name__)

# Constants
IS_COLAB = utils.is_google_colab() or os.getenv("IS_COLAB") == "1"
HF_TOKEN = os.getenv("HF_TOKEN")
CACHE_EXAMPLES = torch.cuda.is_available() and os.getenv("CACHE_EXAMPLES") == "1"

# Create CSS with improved buttons and styling
custom_css = """
.header {
    text-align: center;
    margin-bottom: 2rem;
    background: linear-gradient(to right, #4a69bd, #6a89cc);
    padding: 1.5rem;
    border-radius: 10px;
    color: white;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.title {
    margin: 0;
    font-size: 2.5rem;
    font-weight: 700;
}

.subtitle {
    font-size: 1.1rem;
    margin-top: 0.5rem;
    opacity: 0.9;
}

.subtitle-inline {
    font-size: 1.3rem;
    font-weight: 400;
    opacity: 0.9;
}

.notification {
    background-color: #fff8e1;
    border-left: 5px solid #ffc107;
    padding: 20px;
    margin: 20px 0;
    font-size: 1.2rem;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.notification-title {
    color: #e65100;
    font-size: 1.5rem;
    margin-bottom: 10px;
    font-weight: 600;
}

.en-message {
    margin-bottom: 15px;
}

.jp-message {
    font-weight: 500;
}
"""

# Create the Gradio interface
with gr.Blocks(css=custom_css) as demo:
    gr.HTML("<div class='header'><h1 class='title'>FanFic Illustrator <span class='subtitle-inline'>with Animagine XL 4.0 Opt</span></h1><p class='subtitle'>Illustrate your fan stories with beautiful AI-generated art<br>二次創作ファン小説にAIで魅力的な挿絵を</p></div>")
    
    with gr.Column():
        # Service temporarily unavailable notification
        gr.HTML("""
        <div class="notification">
            <div class="notification-title">Service Temporarily Suspended</div>
            <div class="en-message">
                This service has been temporarily suspended due to frequent ZERO GPU allocation failures.<br>
                You can try it for free using <a herf="https://github.com/webbigdata-jp/python_sample/blob/main/FanFic_Illustrator_demo.ipynb">Google Colab FanFic Illustrator demo</a>
            </div>
            <div class="jp-message">
                ZERO GPUの割当に失敗する事が多すぎるので一時停止しました。<br>
                <a herf="https://github.com/webbigdata-jp/python_sample/blob/main/FanFic_Illustrator_demo.ipynb">Google Colab FanFic Illustrator demo</a>で無料で試す事ができます
            </div>
        </div>
        """)

# Launch the app
if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", share=IS_COLAB)