Spaces:
Running on Zero
Running on Zero
Condensate Titration: show all 512 generated images in a gallery, captioned with level and call
Browse filesFiles changed (2)
- app.py+14-18
- cell_fm/apps/condenseq/pipeline.py+3-2
121 unmodified lines12212312412512612712812913013113213313413513613713813914014114214331 unmodified lines17517617717817918018136 unmodified lines218219220221222223224121 unmodified linesreturn figdef plot_samples(result: pipeline.Result):"""A strip of generated images across the ladder, so the curve is checkable by eye."""imgs, xs = result.images, result.image_intensitiesfig, axes = plt.subplots(1, len(imgs), figsize=(2.0 * len(imgs), 2.3), facecolor=SURFACE)for ax, img, level in zip(np.atleast_1d(axes), imgs, xs):ax.imshow(img, cmap="magma", vmin=0, vmax=1)ax.set_title(f"{level:.0f}", fontsize=10, color=INK)ax.set_xticks([]); ax.set_yticks([])for s in ax.spines.values():s.set_visible(False)fig.suptitle("Generated protein channel across the concentration ladder (a.u.)",fontsize=10, color=MUTED, y=0.04)fig.tight_layout(rect=(0, 0.06, 1, 1))return figdef summary_markdown(result: pipeline.Result) -> str:31 unmodified linescsv_path = os.path.join("/tmp", "pred_vs_intensity.csv")table.to_csv(csv_path, index=False)return plot_curve(result), plot_samples(result), summary_markdown(result), table, csv_path# ---------------------------------------------------------------------------36 unmodified linessummary = gr.Markdown()curve_plot = gr.Plot(label="Condensate titration curve")sample_plot = gr.Plot(label="Generated images")with gr.Accordion("Per-image results", open=False):table = gr.Dataframe(label="pred_vs_intensity", wrap=True)121 unmodified lines12212312412512612712812913013113213313413513631 unmodified lines16816917017117217317436 unmodified lines211212213214215216217218219220121 unmodified linesreturn figdef sample_gallery(result: pipeline.Result):"""Every generated image along the ladder, captioned with its level and call, so the curveis checkable by eye."""magma = matplotlib.colormaps["magma"]calls = ["condensed" if p else "diffuse" for p in result.predictions]return [((magma(np.clip(img, 0, 1))[..., :3] * 255).astype(np.uint8), f"{level:.0f} \u00b7 {call}")for img, level, call in zip(result.images, result.image_intensities, calls)]def summary_markdown(result: pipeline.Result) -> str:31 unmodified linescsv_path = os.path.join("/tmp", "pred_vs_intensity.csv")table.to_csv(csv_path, index=False)return plot_curve(result), sample_gallery(result), summary_markdown(result), table, csv_path# ---------------------------------------------------------------------------36 unmodified linessummary = gr.Markdown()curve_plot = gr.Plot(label="Condensate titration curve")sample_plot = gr.Gallery(label="Generated images (protein channel; intensity level \u00b7 classifier call)",columns=8, height=520, allow_preview=True, object_fit="contain",)with gr.Accordion("Per-image results", open=False):table = gr.Dataframe(label="pred_vs_intensity", wrap=True)
220 unmodified lines22122222322422522622796 unmodified lines324325326327328329330220 unmodified linesaac: float # area above the curve (reentrant dissolution)no_reentrant_auc: floatc_sat: floatimages: np.ndarray = field(repr=False, default=None) # (K, 160, 160) sample panelimage_intensities: np.ndarray = field(repr=False, default=None)96 unmodified linesintensities = intensity_ladder(num_images).numpy()_, window, stats = summarise(intensities, predictions, num_images)panel, panel_x = sample_panel(images, intensities)return Result(sequence=sequence,220 unmodified lines22122222322422522622796 unmodified lines324325326327328329330331220 unmodified linesaac: float # area above the curve (reentrant dissolution)no_reentrant_auc: floatc_sat: floatimages: np.ndarray = field(repr=False, default=None) # (N, 160, 160) every generated imageimage_intensities: np.ndarray = field(repr=False, default=None)96 unmodified linesintensities = intensity_ladder(num_images).numpy()_, window, stats = summarise(intensities, predictions, num_images)# every image, in ladder order, so the gallery shows all of thempanel, panel_x = sample_panel(images, intensities, k=num_images)return Result(sequence=sequence,
app.py+14-18
cell_fm/apps/condenseq/pipeline.py+3-2