import streamlit as st import pyvista as pv from dcgan import DCGAN3D_G import torch import requests import time import numpy as np import streamlit.components.v1 as components url = "https://github.com/LukasMosser/PorousMediaGan/blob/master/checkpoints/berea/berea_generator_epoch_24.pth?raw=true" # If repo is private - we need to add a token in header: resp = requests.get(url) with open('berea_generator_epoch_24.pth', 'wb') as f: f.write(resp.content) time.sleep(5) st.text(resp.status_code) pv.set_plot_theme("document") pl = pv.Plotter(shape=(1, 1), window_size=(800, 800)) netG = DCGAN3D_G(64, 512, 1, 32, 1) netG.load_state_dict(torch.load("berea_generator_epoch_24.pth", map_location=torch.device('cpu'))) z = torch.randn(1, 512, 1, 1, 1) with torch.no_grad(): X = netG(z) st.image((X[0, 0, 32].numpy()+1)/2, output_format="png") img = (X[0, 0].numpy()+1)/2 a = 0.9 # create a uniform grid to sample the function with x_min, y_min, z_min = 0, 0, 0 grid = pv.UniformGrid( dims=img.shape, spacing=(1, 1, 1), origin=(x_min, y_min, z_min), ) x, y, z = grid.points.T # sample and plot values = img.flatten() grid.point_data['my_array'] = values slices = grid.slice_orthogonal() pl.add_mesh(slices, cmap="gray") pl.export_html('pyvista.html') st.header("test html import") view_width = 800 view_height = 800 HtmlFile = open("pyvista.html", 'r', encoding='utf-8') source_code = HtmlFile.read() components.html(source_code, width=view_width, height=view_height)