import os from functools import lru_cache import gradio as gr from app.inference import WARNING, Predictor from app.ui import CSS, DESCRIPTIONS, build_theme @lru_cache(maxsize=1) def predictor(): return Predictor() def classify(path): if not path: raise gr.Error("Please upload a JPEG or PNG satellite patch.") try: result = predictor().predict(path) except (ValueError, OSError, RuntimeError) as exc: raise gr.Error(str(exc)) from exc return ( path, result["probabilities"], f"### {result['label']}\n{DESCRIPTIONS[result['label']]}", ) def build_app(): with gr.Blocks( title="CELYRIX | Mirutex Technologies", analytics_enabled=False, delete_cache=(60, 60), ) as demo: gr.Markdown( "# CELYRIX\nSatellite Land Cover Classification\n\nDeveloped by Mirutex Technologies · Version 1.0.0" ) with gr.Row(): with gr.Column(): image = gr.File( type="filepath", file_types=[".jpg", ".jpeg", ".png"], label="Drop a JPEG or PNG satellite patch", elem_id="satellite-upload", ) preview = gr.Image( label="Uploaded image", interactive=False, height=210 ) button = gr.Button("Classify image", variant="primary") with gr.Column(): label = gr.Label(num_top_classes=5, label="Land-cover probabilities") explanation = gr.Markdown( "Upload an image to run local neural-network inference." ) gr.Markdown(WARNING) gr.Markdown( "**Technical details:** 64×64 RGB input · TensorFlow/Keras CNN trained from scratch · CPU inference. " "Images are processed on this application server; no third-party inference service is used. " "Temporary upload files are removed by the application cache cleanup. " "Research use only; geographic generalization is unverified." ) repo = os.getenv("CELYRIX_MODEL_REPO") if repo: gr.Markdown(f"[Model repository](https://huggingface.co/{repo})") else: gr.Markdown( "Model repository: publication pending; this demo uses local release weights." ) gr.Markdown( "[Dataset and authors](https://github.com/phelber/EuroSAT) · [Official dataset archive](https://zenodo.org/records/7711810) · [Mirutex Technologies](https://mirutex.ru)" ) button.click( classify, image, [preview, label, explanation], api_name="classify", concurrency_limit=1, ) return demo demo = build_app() if __name__ == "__main__": demo.queue(max_size=16).launch( server_name=os.getenv("GRADIO_SERVER_NAME", "127.0.0.1"), max_file_size="10mb", share=False, css=CSS, theme=build_theme(), )