File size: 2,478 Bytes
15d68eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Indic Heritage Studio v2 — Application entry point.

Launches the Gradio web UI exposing all six multimodal pipelines:
  1. Text → Heritage-styled image (SDXL + DreamShaper-XL + per-style LoRA)
  2. Image + style → Stylized image (IP-Adapter XL)
  3. Image → 4-second video (Stable Video Diffusion)
  4. ControlNet (Canny/Depth/OpenPose composition conditioning)
  5. Inpainting (mask + restyle)
  6. Batch processing (multi-GPU parallel)

Usage:
    python app.py
    # then open http://localhost:7860
"""
from __future__ import annotations

import logging
import os
import sys
from pathlib import Path

from dotenv import load_dotenv

load_dotenv()

logging.basicConfig(
    level=os.getenv("LOG_LEVEL", "INFO"),
    format="%(asctime)s | %(levelname)-7s | %(name)s | %(message)s",
    datefmt="%H:%M:%S",
)
log = logging.getLogger("indic-heritage-studio")


def _preflight() -> None:
    """Run sanity checks before starting the UI."""
    root = Path(__file__).resolve().parent
    if str(root) not in sys.path:
        sys.path.insert(0, str(root))

    if not os.getenv("AMD_MODEL_API_KEY"):
        log.warning(
            "AMD_MODEL_API_KEY not set — agent layer will be disabled. "
            "Core generation still works."
        )

    try:
        import torch
        if not torch.cuda.is_available():
            log.warning(
                "torch.cuda.is_available() is False — running on CPU. "
                "Generation will be very slow."
            )
        else:
            n = torch.cuda.device_count()
            log.info("GPU ready: %d device(s) detected — %s",
                     n, torch.cuda.get_device_name(0))
            if n > 1:
                log.info("Multi-GPU mode: %d GPUs available, total %.0f GB VRAM",
                         n, sum(torch.cuda.get_device_properties(i).total_memory
                                for i in range(n)) / 1e9)
    except ImportError:
        log.error("PyTorch not installed. Run: pip install -r requirements.txt")
        sys.exit(1)


def main() -> None:
    _preflight()
    from ui.gradio_app import build_ui

    log.info("Starting Indic Heritage Studio v2 …")
    demo = build_ui()
    demo.launch(
        server_name=os.getenv("GRADIO_SERVER_NAME", "0.0.0.0"),
        server_port=int(os.getenv("GRADIO_SERVER_PORT", "7860")),
        share=False,
        show_error=True,
        inbrowser=False,
        max_threads=8,
    )


if __name__ == "__main__":
    main()