File size: 4,869 Bytes
351ed7b
8a15a25
 
351ed7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
135
136
137
138
139
import gradio as gr
from simulations import finance_demo, quantum_demo, fluid_demo, bio_demo
from poseidon_model import load_model, run_inference_by_domain, run_inference_on_dataset, plot_output, plot_comparison


def run_poseidon_demo(domain, contrast, cmap):
    """
        Loads the POSEIDON model and runs it on synthetic input data
        based on the selected scientific domain (e.g., Finance, Quantum).

        Args:
            domain (str): Selected scientific field.
            contrast (float): Contrast setting for visualization.
            cmap (str): Colormap choice for heatmap.

        Returns:
            Matplotlib figure showing the output.
    """
    model = load_model()
    output = run_inference_by_domain(model, domain)
    return plot_output(output, contrast=contrast, cmap=cmap)



def render_demo(domain):
    """
        Returns a mini-simulation plot and a descriptive explanation
        for the selected domain.

        Args:
            domain (str): One of Finance, Quantum, Fluid Dynamics, Biology.

        Returns:
            Tuple of (plot, explanatory markdown string).
    """

    if domain == "Finance":
        return finance_demo(), (
            "📍 **Finance:** PDEs like Black-Scholes are used to model option pricing. "
            "Imagine fine-tuning Poseidon to forecast derivatives across market regimes!"
        )
    elif domain == "Quantum":
        return quantum_demo(), (
            "📍 **Quantum Mechanics:** Schrödinger's equation is a core PDE in quantum physics. "
            "Could Poseidon learn to generalize across quantum systems?"
        )
    elif domain == "Fluid Dynamics":
        return fluid_demo(), (
            "📍 **Fluid Dynamics:** Poseidon is pretrained here! This sim shows 1D flow, "
            "but Poseidon can do much more."
        )
    elif domain == "Biology / Medicine":
        return bio_demo(), (
            "📍 **Biology:** Reaction-diffusion equations appear in tissue growth and morphogenesis. "
            "Poseidon could help model organ behavior!"
        )
    else:
        return None, "Pick a domain to explore how Poseidon might apply!"



def run_poseidon_real_dataset(dataset_name):
    """
        Loads Poseidon and runs inference on a real scientific dataset from the Hub.

        Args:
            dataset_name (str): Dataset ID from dropdown.

        Returns:
            Matplotlib figure with side-by-side comparison of input vs output.
    """
    model = load_model()
    input_array, output_array = run_inference_on_dataset(model, dataset_name)
    return plot_comparison(input_array, output_array)


# this part defines the app
with gr.Blocks() as demo:
    gr.Markdown("# 🔱 POSEIDON Application Across Scientific Domains 🔱")

    gr.Markdown("### **Welcome to the POSEIDON Playground!**")
    gr.Markdown("Ever dreamed of solving physics equations with a single click? You’re in the right place.")
    gr.Markdown("POSEIDON is a foundation model that learned to solve partial differential equations (PDEs) — the magical "
                "math behind fluid flows, quantum mechanics, financial markets, and even biology!")

    gr.Markdown("## ☑️ 1. Pick a scientific domain to see a simple PDE simulation and Explanation.")
    domain_dropdown = gr.Dropdown(
        ["Finance", "Quantum", "Fluid Dynamics", "Biology / Medicine"],
        label="Choose The Field",
        value="Finance"
    )
    sim_output = gr.Plot()
    sim_text = gr.Markdown()

    domain_dropdown.change(fn=render_demo, inputs=domain_dropdown, outputs=[sim_output, sim_text])

    gr.Markdown("## 🚀 Run a test output from the POSEIDON model based on the chosen domain")

    with gr.Row():
        gr.Markdown("Play with contrast and choose the colormap you prefer.")
        contrast_slider = gr.Slider(0.5, 5.0, value=2.0, step=0.1, label=" Contrast")
        cmap_dropdown = gr.Dropdown(
            ["inferno", "viridis", "plasma"],
            label="Colormap",
            value="inferno"
        )

    with gr.Row():
        poseidon_button = gr.Button("POSEIDON Test Output")
        

    poseidon_plot = gr.Plot()
    poseidon_button.click(
        fn=run_poseidon_demo,
        inputs=[domain_dropdown, contrast_slider, cmap_dropdown],
        outputs=poseidon_plot
    )

    gr.Markdown("# ")

    gr.Markdown("## ☑️ 2. Try POSEIDON on Real Scientific Datasets")
    dataset_dropdown = gr.Dropdown(
        ["fluids.incompressible.Sines", "fluids.compressible.Riemann", "reaction_diffusion.AllenCahn"],
        label="Choose a Real Dataset"
    )
    dataset_button = gr.Button("POSEIDON on Dataset")
    dataset_plot = gr.Plot()

    dataset_button.click(
        fn=run_poseidon_real_dataset,
        inputs=[dataset_dropdown],
        outputs=dataset_plot
    )



if __name__ == "__main__":
    demo.launch()