NNNan commited on
Commit
3731633
·
verified ·
1 Parent(s): feaf142

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +21 -16
README.md CHANGED
@@ -52,30 +52,35 @@ image.show()
52
 
53
  ### 🔄 Flexible Prompt Composition
54
 
55
- The prompts used in UniEM-Gen are highly modular — keywords describing morphology, structure, color, and texture can be freely combined to generate diverse electron micrographs. This compositional flexibility allows users to craft custom prompts by mixing and matching descriptive terms.
56
 
57
- You can randomly sample one term from each of the nine attribute categories defined in the **[UniEM-3M](https://huggingface.co/datasets/NNNan/UniEM-3M)**, then assemble them into a coherent prompt using the following structured template:
58
 
59
  ```text
60
  <microscopy_type> of <subject>: <morphology>. <surface_texture>. <particle_density>. <distribution>. <layering>. <pixel_size_profile>. <color_profile>.
61
- 💬 Replace each <...> placeholder with a real value from the corresponding category.
62
  ```
63
 
64
  ```python
65
  # Sampled attributes from UniEM-3M
66
- from collections import defaultdict
67
- from datasets import load_dataset
68
-
69
- attribute_values = defaultdict(set)
70
- dataset = load_dataset('NNNan/UniEM-3M')
71
-
72
- for attr_dict in dataset['synthesized_data_structured_descriptions']['attribute_description']:
73
- for key, value in attr_dict.items():
74
- attribute_values[key].add(value)
75
-
76
-
77
- # Construct the prompt
78
- prompt = f"{microscopy_type} of {subject}: {morphology}. {surface_texture}. {particle_density}. {distribution}. {layering}. {pixel_size_profile}. {color_profile}."
 
 
 
 
 
79
  print(prompt)
80
  ```
81
 
 
52
 
53
  ### 🔄 Flexible Prompt Composition
54
 
55
+ You can generate structured scientific descriptions by randomly sampling one term from each of the nine attribute categories defined in the **[UniEM-3M](https://huggingface.co/datasets/NNNan/UniEM-3M)**. This repository includes attribute_values.json, which contains all observed values for these attributes, enabling reproducible and diverse prompt generation.
56
 
57
+ Use the following template to assemble the sampled terms into a coherent description:
58
 
59
  ```text
60
  <microscopy_type> of <subject>: <morphology>. <surface_texture>. <particle_density>. <distribution>. <layering>. <pixel_size_profile>. <color_profile>.
61
+ "💬 Replace each <...> placeholder with a real value from the corresponding category."
62
  ```
63
 
64
  ```python
65
  # Sampled attributes from UniEM-3M
66
+ from huggingface_hub import hf_hub_download
67
+ import json
68
+ import random
69
+
70
+ # Download the attribute_values.json file from the repo
71
+ json_path = hf_hub_download(
72
+ repo_id="NNNan/UniEM-Gen",
73
+ filename="attribute_values.json"
74
+ )
75
+
76
+ # Load the attribute values
77
+ with open(json_path, "r", encoding="utf-8") as f:
78
+ attribute_values = json.load(f)
79
+
80
+ # Generate a random description
81
+ template = "{microscopy_type} of {subject}: {morphology}. {surface_texture}. {particle_density}. {distribution}. {layering}. {pixel_size_profile}. {color_profile}."
82
+ sampled = {k: random.choice(list(v)) for k, v in attribute_values.items()}
83
+ prompt = template.format(**sampled)
84
  print(prompt)
85
  ```
86