jannisborn commited on
Commit
fbaddc2
1 Parent(s): 997984a
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: GT4SD - Polymer Blocks
3
  emoji: 💡
4
  colorFrom: green
5
  colorTo: blue
 
1
  ---
2
+ title: GT4SD - Diffusers (image)
3
  emoji: 💡
4
  colorFrom: green
5
  colorTo: blue
app.py CHANGED
@@ -2,30 +2,32 @@ import logging
2
  import pathlib
3
  import gradio as gr
4
  import pandas as pd
5
- from gt4sd.algorithms.generation.polymer_blocks import (
6
- PolymerBlocksGenerator,
7
- PolymerBlocks,
 
 
 
 
 
8
  )
9
-
10
  from gt4sd.algorithms.registry import ApplicationsRegistry
11
 
12
- from utils import draw_grid_generate
13
-
14
  logger = logging.getLogger(__name__)
15
  logger.addHandler(logging.NullHandler())
16
 
17
 
18
- def run_inference(algorithm_version: str, length: float, number_of_samples: int):
19
 
20
- config = PolymerBlocksGenerator(
21
- algorithm_version=algorithm_version,
22
- batch_size=32,
23
- generated_length=length,
24
- )
25
- model = PolymerBlocks(config)
26
- samples = list(model.sample(number_of_samples))
27
 
28
- return draw_grid_generate(samples=samples, n_cols=5, seeds=[])
29
 
30
 
31
  if __name__ == "__main__":
@@ -33,11 +35,10 @@ if __name__ == "__main__":
33
  # Preparation (retrieve all available algorithms)
34
  all_algos = ApplicationsRegistry.list_available()
35
  algos = [
36
- x["algorithm_version"]
37
- for x in list(
38
- filter(lambda x: "PolymerBlocks" in x["algorithm_name"], all_algos)
39
- )
40
  ]
 
41
 
42
  # Load metadata
43
  metadata_root = pathlib.Path(__file__).parent.joinpath("model_cards")
@@ -53,21 +54,14 @@ if __name__ == "__main__":
53
 
54
  demo = gr.Interface(
55
  fn=run_inference,
56
- title="Polymer Blocks",
57
  inputs=[
58
- gr.Dropdown(algos, label="Algorithm version", value="v0"),
59
- gr.Slider(
60
- minimum=5,
61
- maximum=400,
62
- value=100,
63
- label="Maximal sequence length",
64
- step=1,
65
- ),
66
- gr.Slider(
67
- minimum=1, maximum=50, value=10, label="Number of samples", step=1
68
  ),
 
69
  ],
70
- outputs=gr.HTML(label="Output"),
71
  article=article,
72
  description=description,
73
  examples=examples.values.tolist(),
 
2
  import pathlib
3
  import gradio as gr
4
  import pandas as pd
5
+ from gt4sd.algorithms.generation.diffusion import (
6
+ DiffusersGenerationAlgorithm,
7
+ DDPMGenerator,
8
+ DDIMGenerator,
9
+ ScoreSdeGenerator,
10
+ LDMTextToImageGenerator,
11
+ LDMGenerator,
12
+ StableDiffusionGenerator,
13
  )
 
14
  from gt4sd.algorithms.registry import ApplicationsRegistry
15
 
 
 
16
  logger = logging.getLogger(__name__)
17
  logger.addHandler(logging.NullHandler())
18
 
19
 
20
+ def run_inference(model_type: str, prompt: str):
21
 
22
+ config = eval(f"{model_type}(prompt={prompt})")
23
+ if config.modality != "token2image" and prompt != "":
24
+ raise ValueError(
25
+ f"{model_type} is an unconditional generative model, please remove prompt (not={prompt})"
26
+ )
27
+ model = DiffusersGenerationAlgorithm(config)
28
+ image = list(model.sample(1))[0]
29
 
30
+ return image
31
 
32
 
33
  if __name__ == "__main__":
 
35
  # Preparation (retrieve all available algorithms)
36
  all_algos = ApplicationsRegistry.list_available()
37
  algos = [
38
+ x["algorithm_application"]
39
+ for x in list(filter(lambda x: "Diff" in x["algorithm_name"], all_algos))
 
 
40
  ]
41
+ algos = [a for a in algos if not "GeoDiff" in a]
42
 
43
  # Load metadata
44
  metadata_root = pathlib.Path(__file__).parent.joinpath("model_cards")
 
54
 
55
  demo = gr.Interface(
56
  fn=run_inference,
57
+ title="Diffusion-based image generators",
58
  inputs=[
59
+ gr.Dropdown(
60
+ algos, label="Diffusion model", value="StableDiffusionGenerator"
 
 
 
 
 
 
 
 
61
  ),
62
+ gr.Textbox(label="Text prompt", placeholder="A blue tree", lines=1),
63
  ],
64
+ outputs=gr.outputs.Image(type="pil"),
65
  article=article,
66
  description=description,
67
  examples=examples.values.tolist(),
model_cards/article.md CHANGED
@@ -1,40 +1,45 @@
1
  # Model documentation & parameters
2
 
3
- **Algorithm Version**: Which model version to use.
4
 
5
- **Maximal sequence length**: The maximal number of SMILES tokens in the generated molecule.
6
 
7
- **Number of samples**: How many samples should be generated (between 1 and 50).
8
 
9
 
 
10
 
11
- # Model card -- PolymerBlocks
 
 
 
 
 
 
 
12
 
13
- **Model Details**: *PolymerBlocks* is a sequence-based molecular generator tuned to generate blocks of polymers (e.g., catalysts and monomers). The model relies on a Variational Autoencoder architecture as described in [Born et al. (2021; *iScience*)](https://www.sciencedirect.com/science/article/pii/S2589004221002376)
14
 
15
- **Developers**: Matteo Manica and colleagues from IBM Research.
16
 
17
- **Distributors**: Original authors' code integrated into GT4SD.
18
 
19
- **Model date**: Not yet published.
20
 
21
- **Model version**: Only initial model version.
22
-
23
- **Model type**: A sequence-based molecular generator tuned to generate blocks of polymers (e.g., catalysts and monomers).
24
 
25
  **Information about training algorithms, parameters, fairness constraints or other applied approaches, and features**:
26
  N.A.
27
 
28
  **Paper or other resource for more information**:
29
- TBD
30
 
31
  **License**: MIT
32
 
33
- **Where to send questions or comments about the model**: Open an issue on [GT4SD repository](https://github.com/GT4SD/gt4sd-core).
34
 
35
- **Intended Use. Use cases that were envisioned during development**: Chemical research, in particular drug discovery.
36
 
37
- **Primary intended uses/users**: Researchers and computational chemists using the model for model comparison or research exploration purposes.
38
 
39
  **Out-of-scope use cases**: Production-level inference, producing molecules with harmful properties.
40
 
@@ -51,10 +56,12 @@ Model card prototype inspired by [Mitchell et al. (2019)](https://dl.acm.org/doi
51
  ## Citation
52
  TBD, temporarily please cite:
53
  ```bib
54
- @article{manica2022gt4sd,
55
- title={GT4SD: Generative Toolkit for Scientific Discovery},
56
- author={Manica, Matteo and Cadow, Joris and Christofidellis, Dimitrios and Dave, Ashish and Born, Jannis and Clarke, Dean and Teukam, Yves Gaetan Nana and Hoffman, Samuel C and Buchan, Matthew and Chenthamarakshan, Vijil and others},
57
- journal={arXiv preprint arXiv:2207.03928},
58
- year={2022}
 
 
59
  }
60
  ```
 
1
  # Model documentation & parameters
2
 
3
+ **Diffusion model**: Which model version to use.
4
 
5
+ **Prompt**: The text prompt used, only applies to *conditional* diffusion image generators. These are `LDMTextToImageGenerator` and `StableDiffusionGenerator`. The other four models (`DDPMGenerator`, `DDPMGenerator`, `LDMGenerator` and `ScoreSdeGenerator`) are *unconditional*.
6
 
 
7
 
8
 
9
+ # Model card -- Image diffusion models
10
 
11
+ **Model Details**: Six diffusion models for image generation:
12
+ - `LDMTextToImageGenerator`
13
+ - `StableDiffusionGenerator`
14
+ - `DDPMGenerator`
15
+ - `DDPMGenerator`
16
+ - `LDMGenerator`
17
+ - `ScoreSdeGenerator`
18
+ For details, see the [Diffusers docs](https://huggingface.co/docs/diffusers/index)
19
 
20
+ **Developers**: Various developers of above models, wrapped by Diffusers developers into [`diffusers`](https://github.com/huggingface/diffusers)
21
 
22
+ **Distributors**: Diffusers code integrated into GT4SD.
23
 
24
+ **Model date**: 2022.
25
 
26
+ **Model version**: Diffusion models, checkpoints provided and distributed by [`diffusers`](https://github.com/huggingface/diffusers).
27
 
28
+ **Model type**: Various, see [`diffusers`](https://github.com/huggingface/diffusers) docs.
 
 
29
 
30
  **Information about training algorithms, parameters, fairness constraints or other applied approaches, and features**:
31
  N.A.
32
 
33
  **Paper or other resource for more information**:
34
+ N.A.
35
 
36
  **License**: MIT
37
 
38
+ **Where to send questions or comments about the model**: Open an issue on [`diffusers`](https://github.com/huggingface/diffusers) repo.
39
 
40
+ **Intended Use. Use cases that were envisioned during development**: Computer vision researchers experimenting with image generative models.
41
 
42
+ **Primary intended uses/users**: Computer vision researchers
43
 
44
  **Out-of-scope use cases**: Production-level inference, producing molecules with harmful properties.
45
 
 
56
  ## Citation
57
  TBD, temporarily please cite:
58
  ```bib
59
+ @misc{von-platen-etal-2022-diffusers,
60
+ author = {Patrick von Platen and Suraj Patil and Anton Lozhkov and Pedro Cuenca and Nathan Lambert and Kashif Rasul and Mishig Davaadorj and Thomas Wolf},
61
+ title = {Diffusers: State-of-the-art diffusion models},
62
+ year = {2022},
63
+ publisher = {GitHub},
64
+ journal = {GitHub repository},
65
+ howpublished = {\url{https://github.com/huggingface/diffusers}}
66
  }
67
  ```
model_cards/description.md CHANGED
@@ -1,6 +1,6 @@
1
  <img align="right" src="https://raw.githubusercontent.com/GT4SD/gt4sd-core/main/docs/_static/gt4sd_logo.png" alt="logo" width="120" >
2
 
3
- *PolymerBlocks* is a sequence-based molecular generator tuned to generate blocks of polymers (e.g., catalysts and monomers). The model relies on a Variational Autoencoder architecture as described in [Born et al. (2021; *iScience*)](https://www.sciencedirect.com/science/article/pii/S2589004221002376)
4
 
5
  For **examples** and **documentation** of the model parameters, please see below.
6
  Moreover, we provide a **model card** ([Mitchell et al. (2019)](https://dl.acm.org/doi/abs/10.1145/3287560.3287596?casa_token=XD4eHiE2cRUAAAAA:NL11gMa1hGPOUKTAbtXnbVQBDBbjxwcjGECF_i-WC_3g1aBgU1Hbz_f2b4kI_m1in-w__1ztGeHnwHs)) at the bottom of this page.
 
1
  <img align="right" src="https://raw.githubusercontent.com/GT4SD/gt4sd-core/main/docs/_static/gt4sd_logo.png" alt="logo" width="120" >
2
 
3
+ This UI provides access to various diffusion-based image generators implemented in the [`diffusers`](https://github.com/huggingface/diffusers) library, wrapped and re-distributed by GT4SD.
4
 
5
  For **examples** and **documentation** of the model parameters, please see below.
6
  Moreover, we provide a **model card** ([Mitchell et al. (2019)](https://dl.acm.org/doi/abs/10.1145/3287560.3287596?casa_token=XD4eHiE2cRUAAAAA:NL11gMa1hGPOUKTAbtXnbVQBDBbjxwcjGECF_i-WC_3g1aBgU1Hbz_f2b4kI_m1in-w__1ztGeHnwHs)) at the bottom of this page.
model_cards/examples.csv CHANGED
@@ -1 +1,2 @@
1
- v0,100,10
 
 
1
+ LDMGenerator,
2
+ LDMTextToImageGenerator,Generative models on the moon