|
"""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_dotenv() |
|
|
|
|
|
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) |
|
|
|
|
|
|
|
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(): |
|
|
|
_ = self.generate_tab.create_ui() |
|
_ = self.identify_tab.create_ui() |
|
_ = self.train_tab.create_ui() |
|
_ = self.french_style_tab.create_ui() |
|
|
|
|
|
self._setup_cross_tab_interactions() |
|
|
|
|
|
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.""" |
|
|
|
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() |
|
|
|
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() |
|
|