File size: 3,113 Bytes
25bcd98 3e346a2 006130a 3e346a2 25bcd98 3e346a2 7e5d515 3e346a2 25bcd98 3e346a2 7efd7d2 5aeda0b 7efd7d2 25bcd98 3e346a2 5aeda0b b24c04f 3e346a2 b24c04f 3e346a2 b24c04f 3e346a2 b9ba091 b24c04f 3e346a2 5aeda0b b24c04f 3e346a2 b24c04f 3e346a2 b24c04f df7e5d4 b24c04f 3e346a2 b24c04f 3e346a2 b24c04f 3e346a2 b24c04f 3e346a2 ba27a18 b24c04f 3e346a2 8608d22 b24c04f 3e346a2 8608d22 07f3e95 3e346a2 b24c04f 3e346a2 b24c04f 3e346a2 8608d22 3e346a2 07252bb b24c04f 3e346a2 b24c04f |
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 |
"""Main Flowerify application - UI-only with clean separation of concerns.
Refactored to use modular architecture with FLUX support.
"""
import os
import sys
import traceback
import gradio as gr
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
# Add src directory to path for imports
src_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "src")
if src_path not in sys.path:
sys.path.insert(0, src_path)
# Initialize config early to setup cache paths before model imports
# ruff: noqa: E402
from core.config import config
from ui.french_style.french_style_tab import FrenchStyleTab
from ui.generate.generate_tab import GenerateTab
from ui.identify.identify_tab import IdentifyTab
from ui.train.train_tab import TrainTab
print(f"π§ Environment: {'HF Spaces' if config.is_hf_spaces else 'Local'}")
print(f"π§ Device: {config.device}, dtype: {config.dtype}")
class FlowerifyApp:
"""Main application class for Flowerify."""
def __init__(self):
self.generate_tab = GenerateTab()
self.identify_tab = IdentifyTab()
self.train_tab = TrainTab()
self.french_style_tab = FrenchStyleTab()
def create_interface(self) -> gr.Blocks:
"""Create the main Gradio interface."""
with gr.Blocks(title="πΈ Flowerify - AI Flower Generator & Identifier") as demo:
gr.Markdown("# πΈ Flowerfy β Text β Image + Flower Identifier")
with gr.Tabs():
# Create each tab
_ = self.generate_tab.create_ui()
_ = self.identify_tab.create_ui()
_ = self.train_tab.create_ui()
_ = self.french_style_tab.create_ui()
# Wire cross-tab interactions
self._setup_cross_tab_interactions()
# Initialize data on load
demo.load(
self.train_tab._count_training_images,
outputs=[self.train_tab.data_status],
)
return demo
def _setup_cross_tab_interactions(self):
"""Setup interactions between tabs."""
# Auto-send generated image to Identify tab
self.generate_tab.output_image.change(
self.identify_tab.set_image,
inputs=self.generate_tab.output_image,
outputs=self.identify_tab.image_input,
)
def launch(self, **kwargs):
"""Launch the application."""
demo = self.create_interface()
# Add share=True for HF Spaces compatibility
if config.is_hf_spaces:
kwargs.setdefault("share", True)
return demo.queue().launch(**kwargs)
def main():
"""Main entry point."""
try:
print("πΈ Starting Flowerify (SDXL models)")
print("Loading models and initializing UI...")
app = FlowerifyApp()
app.launch()
except KeyboardInterrupt:
print("\nπ Application stopped by user")
except Exception as e:
print(f"β Error starting application: {e}")
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()
|