LensCraft / app.py
abreza's picture
Initial commit
bdf752e
import gradio as gr
from gradio_rerun import Rerun
from data.loader import load_simulation_data
from visualization.visualizer import visualize_simulation
def update_simulation_dropdown(file):
simulations, descriptions = load_simulation_data(file)
return gr.Dropdown(
choices=descriptions if descriptions else [],
value=None,
allow_custom_value=False
)
def create_app():
with gr.Blocks() as demo:
gr.Markdown("""
# Camera Simulation Visualizer
Upload a JSON file containing camera simulation data and select a simulation to visualize.
""")
with gr.Row():
file_input = gr.File(
label="Upload Simulation JSON",
file_types=[".json"]
)
simulation_dropdown = gr.Dropdown(
label="Select Simulation",
choices=[],
type="index",
scale=2
)
frame_input = gr.Textbox(
label="Frame Selection",
placeholder="E.g. 1-30, 35, 40-50 (leave empty for all frames)"
)
with gr.Row():
viewer = Rerun(streaming=False)
file_input.change(
update_simulation_dropdown,
inputs=[file_input],
outputs=[simulation_dropdown]
)
simulation_dropdown.change(
visualize_simulation,
inputs=[file_input, simulation_dropdown, frame_input],
outputs=[viewer]
)
frame_input.change(
visualize_simulation,
inputs=[file_input, simulation_dropdown, frame_input],
outputs=[viewer]
)
return demo
if __name__ == "__main__":
demo = create_app()
demo.queue().launch(share=False)