heaversm commited on
Commit
d715409
·
1 Parent(s): 2fd72f3

finish interactivity

Browse files
Files changed (1) hide show
  1. app.py +147 -13
app.py CHANGED
@@ -1,12 +1,144 @@
1
  import gradio as gr
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  css = """
4
  .plugin-accordion button span:first-child {
5
  font-size: 1.25rem !important;
6
  }
 
 
 
 
 
 
 
 
7
  """
8
 
9
- with gr.Blocks(css=css) as pipeline_builder:
 
 
 
 
 
 
 
 
 
10
  gr.Markdown("# 🚰 Impact Framework Pipeline Builder")
11
  gr.Markdown("Visually construct your Impact Framework manifest file pipeline with this helpful interface.")
12
 
@@ -23,7 +155,7 @@ with gr.Blocks(css=css) as pipeline_builder:
23
  with gr.Row():
24
  plugin_selector = gr.Dropdown(["Watt-Time","CO2.js","TDP Finder","Cloud Metadata"], label="Plugin",value="Cloud Metadata",interactive=True,info="Plugins available on the Impact Framework Registry")
25
  with gr.Row():
26
- plugin_selector_submit = gr.Button("Configure Plugin")
27
 
28
  with gr.Row(elem_classes=["dependent-row"],elem_id="plugin-config-row", variant="panel"):
29
  with gr.Column():
@@ -32,18 +164,21 @@ with gr.Blocks(css=css) as pipeline_builder:
32
  with gr.Row():
33
  gr.Markdown("### Cloud Metadata")
34
  with gr.Row(variant="panel"):
35
- plugin_input_1 = gr.Dropdown(["AWS","GCP","Azure","Other"], label="Cloud Vendor", info="Where is your data hosted?",interactive=True,value="AWS")
36
- plugin_input_2 = gr.Dropdown(["C5 Metal","d3.xlarge","m5.large"], label="Cloud Instance", info="Wnat cloud instance is your server using?",interactive=True,value="m5.large",elem_classes=["dependent-dropdown"])
37
  with gr.Row():
38
- plugin_input_finder_btn = gr.Button("Help me find my inputs")
39
- plugin_input_finder_btn = gr.Button("Submit configuration",variant="primary")
40
 
41
 
42
 
43
  with gr.Row(elem_classes=["dependent-row"],elem_id="plugin-metadata-inputs-row", variant="panel"):
44
  with gr.Row():
45
  gr.Markdown("## Find your Cloud Metadata inputs")
46
- plugin_input_finder_url = gr.Textbox(placeholder="https://[your_website.com]", label="Your website URL", info="If you are measuring energy based on a hosted website, enter the URL")
 
 
 
47
 
48
  with gr.Row(elem_classes=["dependent-row"],elem_id="plugin-outputs-row", variant="panel"):
49
  with gr.Column():
@@ -72,13 +207,12 @@ with gr.Blocks(css=css) as pipeline_builder:
72
  with gr.Row(variant="panel"):
73
  gr.Textbox(value="64 / 64",label="used / available")
74
 
75
- with gr.Row(elem_classes=["dependent-row"],elem_id="plugin-add-submit-row", variant="panel"):
76
- gr.Button("Add Another Plugin",variant="secondary",interactive=False)
77
- gr.Button("Generate Manifest",variant="primary")
78
-
79
 
 
 
80
 
81
- #btn = gr.Button("Run")
82
- #btn.click(fn=update, inputs=inp, outputs=out)
83
 
84
  pipeline_builder.launch()
 
1
  import gradio as gr
2
 
3
+ js = """
4
+ function appJS() {
5
+ document.getElementById("plugin-selector-submit").addEventListener("click", function() {
6
+ document.getElementById("plugin-config-row").classList.toggle("active",true);
7
+ });
8
+
9
+ document.getElementById("plugin-input-finder-btn").addEventListener("click", function() {
10
+ document.getElementById("plugin-metadata-inputs-row").classList.toggle("active",true);
11
+ });
12
+
13
+ document.getElementById("plugin-input-finder-submit").addEventListener("click", function() {
14
+ document.getElementById("plugin-metadata-inputs-row").classList.toggle("active",false);
15
+ });
16
+
17
+ document.getElementById("plugin-config-submit").addEventListener("click", function() {
18
+ document.getElementById("plugin-outputs-row").classList.toggle("active",true);
19
+ });
20
+
21
+ document.getElementById("generate-manifest-btn").addEventListener("click", function() {
22
+ // Content of your YAML file
23
+ const yamlContent = `
24
+ name: My Manifest File
25
+ description: My First Manifest File 💚
26
+ initialize:
27
+ outputs: ['yaml']
28
+ plugins:
29
+ group-by:
30
+ path: 'builtin'
31
+ method: GroupBy
32
+ operational-carbon:
33
+ path: '@grnsft/if-plugins'
34
+ method: Multiply
35
+ global-config:
36
+ input-parameters: ['cpu/energy', 'grid/carbon-intensity']
37
+ output-parameter: 'carbon'
38
+ watttime:
39
+ path: '@grnsft/if-unofficial-plugins'
40
+ method: WattTimeGridEmissions
41
+ teads-curve:
42
+ path: '@grnsft/if-unofficial-plugins'
43
+ method: TeadsCurve
44
+ global-config:
45
+ interpolation: spline
46
+ cloud-metadata:
47
+ method: CloudMetadata
48
+ path: "@grnsft/if-plugins"
49
+ mock-observations:
50
+ path: '@grnsft/if-plugins'
51
+ method: MockObservations
52
+ global-config:
53
+ timestamp-from: '2024-03-05T00:00:00.000Z'
54
+ timestamp-to: '2024-03-05T00:01:00.000Z'
55
+ duration: 10
56
+ components:
57
+ - name: server-1
58
+ cloud/instance-type: Standard_E64_v3
59
+ cloud/region: westus3
60
+ - name: server-2
61
+ cloud/instance-type: Standard_E64_v3
62
+ cloud/region: westus3
63
+ generators:
64
+ common:
65
+ cloud/vendor: azure
66
+ randint:
67
+ cpu/utilization:
68
+ min: 1
69
+ max: 99
70
+ 'time-sync':
71
+ method: TimeSync
72
+ path: "builtin"
73
+ global-config:
74
+ start-time: '2024-03-05T00:00:00.000Z'
75
+ end-time: '2024-03-05T00:01:00.000Z'
76
+ interval: 5
77
+ allow-padding: true
78
+ tree:
79
+ pipeline:
80
+ - mock-observations #provides sample usage data from a given geographic region with a simulated cpu / memory utilization.
81
+ - group-by #groups inputs, in this case cloud and region
82
+ - time-sync #standardizes the time format of observations
83
+ - cloud-metadata #determine an instance's physical processor and thermal design power (TDP) based on its instance name (cloud vendor e.g. aws and instance type e.g. m5.large)
84
+ - watttime #determine the carbon intensity of the grid based on the region (e.g. CAISO)
85
+ - teads-curve #estimating CPU usages across varying type of CPUs using a Teads Curve (requires CPU TDP, Utilization, and Duration)
86
+ - operational-carbon #combines two or more elements in an array, in this case energy in kWH and grid carbon intensity)
87
+ defaults:
88
+ config:
89
+ group-by:
90
+ group:
91
+ - cloud/region
92
+ - name
93
+ inputs: null
94
+ `;
95
+
96
+ // Create a Blob object from the YAML content
97
+ const blob = new Blob([yamlContent], { type: "text/yaml" });
98
+
99
+ // Create a temporary anchor element
100
+ const a = document.createElement("a");
101
+ const url = window.URL.createObjectURL(blob);
102
+
103
+ // Set the attributes for downloading
104
+ a.href = url;
105
+ a.download = "data.yaml";
106
+
107
+ // Programmatically click the anchor element to initiate download
108
+ a.click();
109
+
110
+ // Clean up resources
111
+ window.URL.revokeObjectURL(url);
112
+ //document.body.removeChild(element);
113
+ });
114
+
115
+ }
116
+ """
117
+
118
  css = """
119
  .plugin-accordion button span:first-child {
120
  font-size: 1.25rem !important;
121
  }
122
+
123
+ .dependent-row {
124
+ display: none !important;
125
+ }
126
+
127
+ .dependent-row.active {
128
+ display: block !important;
129
+ }
130
  """
131
 
132
+ def populate_plugin_inputs():
133
+ return [gr.Dropdown(["Select Vendor","AWS","GCP","Azure","Other"], label="Cloud Vendor", info="Where is your data hosted?",interactive=True,value="AWS",elem_id="plugin_input_1",elem_classes=["dropdown-one-option"]), gr.Dropdown(["Select Instance","C5 Metal","d3.xlarge","m5.large"], label="Cloud Instance", info="Wnat cloud instance is your server using?",interactive=False,value="m5.large",elem_classes=["dependent-dropdown"],elem_id="plugin_input_2"),gr.Button("Help me find my inputs", elem_id="plugin-input-finder-btn",visible=False)]
134
+
135
+ def populate_plugin_input_1():
136
+ return gr.Dropdown(["Select Vendor","AWS","GCP","Azure","Other"], label="Cloud Vendor", info="Where is your data hosted?",interactive=True,value="AWS",elem_id="plugin_input_1",elem_classes=["dropdown-one-option"])
137
+
138
+ def populate_plugin_input_2():
139
+ return gr.Dropdown(["Select Instance","C5 Metal","d3.xlarge","m5.large"], label="Cloud Instance", info="Wnat cloud instance is your server using?",interactive=False,value="m5.large",elem_classes=["dependent-dropdown"],elem_id="plugin_input_2")
140
+
141
+ with gr.Blocks(css=css,js=js) as pipeline_builder:
142
  gr.Markdown("# 🚰 Impact Framework Pipeline Builder")
143
  gr.Markdown("Visually construct your Impact Framework manifest file pipeline with this helpful interface.")
144
 
 
155
  with gr.Row():
156
  plugin_selector = gr.Dropdown(["Watt-Time","CO2.js","TDP Finder","Cloud Metadata"], label="Plugin",value="Cloud Metadata",interactive=True,info="Plugins available on the Impact Framework Registry")
157
  with gr.Row():
158
+ plugin_selector_submit = gr.Button("Configure Plugin",elem_id="plugin-selector-submit")
159
 
160
  with gr.Row(elem_classes=["dependent-row"],elem_id="plugin-config-row", variant="panel"):
161
  with gr.Column():
 
164
  with gr.Row():
165
  gr.Markdown("### Cloud Metadata")
166
  with gr.Row(variant="panel"):
167
+ plugin_input_1 = gr.Dropdown(["Select Vendor","AWS","GCP","Azure","Other"], label="Cloud Vendor", info="Where is your data hosted?",interactive=True,value="Select Vendor",elem_id="plugin_input_1",elem_classes=["dropdown-one-option"])
168
+ plugin_input_2 = gr.Dropdown(["Select Instance","C5 Metal","d3.xlarge","m5.large"], label="Cloud Instance", info="Wnat cloud instance is your server using?",interactive=True,value="Select Instance",elem_classes=["dependent-dropdown"],elem_id="plugin_input_2")
169
  with gr.Row():
170
+ plugin_input_finder_btn = gr.Button("Help me find my inputs", elem_id="plugin-input-finder-btn")
171
+ plugin_config_submit = gr.Button("Submit configuration",variant="primary",elem_id="plugin-config-submit")
172
 
173
 
174
 
175
  with gr.Row(elem_classes=["dependent-row"],elem_id="plugin-metadata-inputs-row", variant="panel"):
176
  with gr.Row():
177
  gr.Markdown("## Find your Cloud Metadata inputs")
178
+ with gr.Row():
179
+ plugin_input_finder_url = gr.Textbox(placeholder="https://[your_website.com]", label="Your website URL", info="If you are measuring energy based on a hosted website, enter the URL",value="https://mywebsite.com",interactive=False)
180
+ with gr.Row():
181
+ plugin_input_finder_submit = gr.Button("Find Inputs",elem_id="plugin-input-finder-submit")
182
 
183
  with gr.Row(elem_classes=["dependent-row"],elem_id="plugin-outputs-row", variant="panel"):
184
  with gr.Column():
 
207
  with gr.Row(variant="panel"):
208
  gr.Textbox(value="64 / 64",label="used / available")
209
 
210
+ with gr.Row(elem_id="plugin-add-submit-row", variant="panel"):
211
+ gr.Button("Add Another Plugin",variant="secondary",interactive=False)
212
+ generate_manifest_btn = gr.Button("Generate Manifest",variant="primary",elem_id="generate-manifest-btn")
 
213
 
214
+ plugin_input_finder_submit.click(fn=populate_plugin_inputs, outputs=[plugin_input_1,plugin_input_2,plugin_input_finder_btn])
215
+ plugin_config_submit.click(fn=populate_plugin_inputs, outputs=[plugin_input_1,plugin_input_2,plugin_input_finder_btn])
216
 
 
 
217
 
218
  pipeline_builder.launch()