elismasilva commited on
Commit
0c29311
·
verified ·
1 Parent(s): 98b69f4

Upload folder using huggingface_hub

Browse files
Files changed (6) hide show
  1. README.md +29 -38
  2. app.py +20 -52
  3. space.py +28 -38
  4. src/README.md +29 -38
  5. src/demo/app.py +20 -52
  6. src/demo/space.py +28 -38
README.md CHANGED
@@ -36,6 +36,7 @@ The **PropertySheet** component for Gradio allows you to automatically generate
36
  - **Theme-Aware**: Designed to look and feel native in all Gradio themes.
37
  - **Dynamic Updates**: Supports advanced patterns where changing one field (e.g., a model selector) can dynamically update the options of another field (e.g., a sampler dropdown).
38
 
 
39
  ## Installation
40
 
41
  ```bash
@@ -51,6 +52,8 @@ import gradio as gr
51
  from dataclasses import dataclass, field, asdict
52
  from typing import Literal
53
  from gradio_propertysheet import PropertySheet
 
 
54
 
55
  # --- 1. Dataclass Definitions ---
56
 
@@ -109,45 +112,32 @@ initial_env_config = EnvironmentConfig()
109
  sampler_settings_map_py = {"Euler": EulerSettings(), "DPM++ 2M Karras": DPM_Settings(), "UniPC": None}
110
  model_settings_map_py = {"SDXL 1.0": DPM_Settings(), "Stable Diffusion 1.5": EulerSettings(), "Pony": None}
111
 
112
- # --- 3. CSS and JavaScript Loading ---
113
-
114
- # Load external CSS file if it exists
115
- script_path = Path(__file__).resolve()
116
- script_dir = script_path.parent
117
- css_path = script_dir / "custom.css"
118
- flyout_css = ""
119
- if css_path.exists():
120
- with open(css_path, "r", encoding="utf8") as file:
121
- flyout_css = file.read()
122
-
123
- # JavaScript for positioning the flyout panel
124
- head_script = f"""
125
- <script>
126
- function position_flyout(anchorId) {{
127
- setTimeout(() => {{
128
- const anchorRow = document.getElementById(anchorId).closest('.fake-input-container');
129
- const flyoutElem = document.getElementById('flyout_panel');
130
-
131
- if (anchorRow && flyoutElem && flyoutElem.style.display !== 'none') {{
132
- const anchorRect = anchorRow.getBoundingClientRect();
133
- const containerRect = anchorRow.closest('.flyout-context-area').getBoundingClientRect();
134
-
135
- const flyoutWidth = flyoutElem.offsetWidth;
136
- const flyoutHeight = flyoutElem.offsetHeight;
137
 
138
- const topPosition = (anchorRect.top - containerRect.top) + (anchorRect.height / 2) - (flyoutHeight / 2);
139
- const leftPosition = (anchorRect.left - containerRect.left) + (anchorRect.width / 2) - (flyoutWidth / 2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
- flyoutElem.style.top = `${{topPosition}}px`;
142
- flyoutElem.style.left = `${{leftPosition}}px`;
143
- }}
144
- }}, 50);
145
- }}
146
- </script>
147
- """
148
 
149
  # --- 4. Gradio App Build ---
150
- with gr.Blocks(css=flyout_css, head=head_script, title="PropertySheet Demos") as demo:
 
151
  gr.Markdown("# PropertySheet Component Demos")
152
 
153
  with gr.Tabs():
@@ -309,9 +299,10 @@ with gr.Blocks(css=flyout_css, head=head_script, title="PropertySheet Demos") as
309
  return {
310
  sampler_ear_btn: update_ear_visibility(sampler_val, sampler_settings_map_py),
311
  model_ear_btn: update_ear_visibility(model_val, model_settings_map_py)
312
- }
313
- demo.load(fn=initial_flyout_setup, inputs=[sampler_dd, model_dd], outputs=[sampler_ear_btn, model_ear_btn])
314
-
 
315
  if __name__ == "__main__":
316
  demo.launch()
317
  ```
 
36
  - **Theme-Aware**: Designed to look and feel native in all Gradio themes.
37
  - **Dynamic Updates**: Supports advanced patterns where changing one field (e.g., a model selector) can dynamically update the options of another field (e.g., a sampler dropdown).
38
 
39
+
40
  ## Installation
41
 
42
  ```bash
 
52
  from dataclasses import dataclass, field, asdict
53
  from typing import Literal
54
  from gradio_propertysheet import PropertySheet
55
+ from gradio_headinjector import HeadInjector
56
+
57
 
58
  # --- 1. Dataclass Definitions ---
59
 
 
112
  sampler_settings_map_py = {"Euler": EulerSettings(), "DPM++ 2M Karras": DPM_Settings(), "UniPC": None}
113
  model_settings_map_py = {"SDXL 1.0": DPM_Settings(), "Stable Diffusion 1.5": EulerSettings(), "Pony": None}
114
 
115
+ # --- 3. CSS & JS Injection function ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
+ def inject_assets():
118
+ """
119
+ This function prepares the payload of CSS and JS code. It's called by the
120
+ demo.load() event listener when the Gradio app starts.
121
+ """
122
+ # Inline code
123
+ css_code = ""
124
+ js_code = ""
125
+
126
+ # Read from files
127
+ try:
128
+ with open("custom.css", "r", encoding="utf-8") as f:
129
+ css_code += f.read() + "\n"
130
+ with open("custom.js", "r", encoding="utf-8") as f:
131
+ js_code += f.read() + "\n"
132
+ except FileNotFoundError as e:
133
+ print(f"Warning: Could not read asset file: {e}")
134
+
135
+ return {"js": js_code, "css": css_code}
136
 
 
 
 
 
 
 
 
137
 
138
  # --- 4. Gradio App Build ---
139
+ with gr.Blocks(title="PropertySheet Demos") as demo:
140
+ head_injector = HeadInjector()
141
  gr.Markdown("# PropertySheet Component Demos")
142
 
143
  with gr.Tabs():
 
299
  return {
300
  sampler_ear_btn: update_ear_visibility(sampler_val, sampler_settings_map_py),
301
  model_ear_btn: update_ear_visibility(model_val, model_settings_map_py)
302
+ }
303
+ demo.load(fn=inject_assets, inputs=None, outputs=[head_injector]
304
+ ).then(fn=initial_flyout_setup, inputs=[sampler_dd, model_dd], outputs=[sampler_ear_btn, model_ear_btn])
305
+
306
  if __name__ == "__main__":
307
  demo.launch()
308
  ```
app.py CHANGED
@@ -6,25 +6,6 @@ from typing import Literal
6
  from gradio_propertysheet import PropertySheet
7
  from gradio_headinjector import HeadInjector
8
 
9
- def inject_assets():
10
- """
11
- This function prepares the payload of CSS and JS code. It's called by the
12
- demo.load() event listener when the Gradio app starts.
13
- """
14
- # Inline code
15
- css_code = ""
16
- js_code = ""
17
-
18
- # Read from files
19
- try:
20
- with open("custom.css", "r", encoding="utf-8") as f:
21
- css_code += f.read() + "\n"
22
- with open("custom.js", "r", encoding="utf-8") as f:
23
- js_code += f.read() + "\n"
24
- except FileNotFoundError as e:
25
- print(f"Warning: Could not read asset file: {e}")
26
-
27
- return {"js": js_code, "css": css_code}
28
 
29
  # --- 1. Dataclass Definitions ---
30
 
@@ -83,42 +64,28 @@ initial_env_config = EnvironmentConfig()
83
  sampler_settings_map_py = {"Euler": EulerSettings(), "DPM++ 2M Karras": DPM_Settings(), "UniPC": None}
84
  model_settings_map_py = {"SDXL 1.0": DPM_Settings(), "Stable Diffusion 1.5": EulerSettings(), "Pony": None}
85
 
86
- # --- 3. CSS and JavaScript Loading ---
87
 
88
- # Load external CSS file if it exists
89
- # script_path = Path(__file__).resolve()
90
- # script_dir = script_path.parent
91
- # css_path = script_dir / "custom.css"
92
- # flyout_css = ""
93
- # if css_path.exists():
94
- # with open(css_path, "r", encoding="utf8") as file:
95
- # flyout_css = file.read()
96
 
97
- # JavaScript for positioning the flyout panel
98
- # head_script = f"""
99
- # <script>
100
- # function position_flyout(anchorId) {{
101
- # setTimeout(() => {{
102
- # const anchorRow = document.getElementById(anchorId).closest('.fake-input-container');
103
- # const flyoutElem = document.getElementById('flyout_panel');
104
-
105
- # if (anchorRow && flyoutElem && flyoutElem.style.display !== 'none') {{
106
- # const anchorRect = anchorRow.getBoundingClientRect();
107
- # const containerRect = anchorRow.closest('.flyout-context-area').getBoundingClientRect();
108
-
109
- # const flyoutWidth = flyoutElem.offsetWidth;
110
- # const flyoutHeight = flyoutElem.offsetHeight;
111
 
112
- # const topPosition = (anchorRect.top - containerRect.top) + (anchorRect.height / 2) - (flyoutHeight / 2);
113
- # const leftPosition = (anchorRect.left - containerRect.left) + (anchorRect.width / 2) - (flyoutWidth / 2);
114
 
115
- # flyoutElem.style.top = `${{topPosition}}px`;
116
- # flyoutElem.style.left = `${{leftPosition}}px`;
117
- # }}
118
- # }}, 50);
119
- # }}
120
- # </script>
121
- # # """
122
 
123
  # --- 4. Gradio App Build ---
124
  with gr.Blocks(title="PropertySheet Demos") as demo:
@@ -285,7 +252,8 @@ with gr.Blocks(title="PropertySheet Demos") as demo:
285
  sampler_ear_btn: update_ear_visibility(sampler_val, sampler_settings_map_py),
286
  model_ear_btn: update_ear_visibility(model_val, model_settings_map_py)
287
  }
288
- demo.load(fn=inject_assets, inputs=None, outputs=[head_injector]).then(fn=initial_flyout_setup, inputs=[sampler_dd, model_dd], outputs=[sampler_ear_btn, model_ear_btn])
 
289
 
290
  if __name__ == "__main__":
291
  demo.launch()
 
6
  from gradio_propertysheet import PropertySheet
7
  from gradio_headinjector import HeadInjector
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # --- 1. Dataclass Definitions ---
11
 
 
64
  sampler_settings_map_py = {"Euler": EulerSettings(), "DPM++ 2M Karras": DPM_Settings(), "UniPC": None}
65
  model_settings_map_py = {"SDXL 1.0": DPM_Settings(), "Stable Diffusion 1.5": EulerSettings(), "Pony": None}
66
 
67
+ # --- 3. CSS & JS Injection function ---
68
 
69
+ def inject_assets():
70
+ """
71
+ This function prepares the payload of CSS and JS code. It's called by the
72
+ demo.load() event listener when the Gradio app starts.
73
+ """
74
+ # Inline code
75
+ css_code = ""
76
+ js_code = ""
77
 
78
+ # Read from files
79
+ try:
80
+ with open("custom.css", "r", encoding="utf-8") as f:
81
+ css_code += f.read() + "\n"
82
+ with open("custom.js", "r", encoding="utf-8") as f:
83
+ js_code += f.read() + "\n"
84
+ except FileNotFoundError as e:
85
+ print(f"Warning: Could not read asset file: {e}")
 
 
 
 
 
 
86
 
87
+ return {"js": js_code, "css": css_code}
 
88
 
 
 
 
 
 
 
 
89
 
90
  # --- 4. Gradio App Build ---
91
  with gr.Blocks(title="PropertySheet Demos") as demo:
 
252
  sampler_ear_btn: update_ear_visibility(sampler_val, sampler_settings_map_py),
253
  model_ear_btn: update_ear_visibility(model_val, model_settings_map_py)
254
  }
255
+ demo.load(fn=inject_assets, inputs=None, outputs=[head_injector]
256
+ ).then(fn=initial_flyout_setup, inputs=[sampler_dd, model_dd], outputs=[sampler_ear_btn, model_ear_btn])
257
 
258
  if __name__ == "__main__":
259
  demo.launch()
space.py CHANGED
@@ -44,6 +44,8 @@ import gradio as gr
44
  from dataclasses import dataclass, field, asdict
45
  from typing import Literal
46
  from gradio_propertysheet import PropertySheet
 
 
47
 
48
  # --- 1. Dataclass Definitions ---
49
 
@@ -102,45 +104,32 @@ initial_env_config = EnvironmentConfig()
102
  sampler_settings_map_py = {"Euler": EulerSettings(), "DPM++ 2M Karras": DPM_Settings(), "UniPC": None}
103
  model_settings_map_py = {"SDXL 1.0": DPM_Settings(), "Stable Diffusion 1.5": EulerSettings(), "Pony": None}
104
 
105
- # --- 3. CSS and JavaScript Loading ---
106
-
107
- # Load external CSS file if it exists
108
- script_path = Path(__file__).resolve()
109
- script_dir = script_path.parent
110
- css_path = script_dir / "custom.css"
111
- flyout_css = ""
112
- if css_path.exists():
113
- with open(css_path, "r", encoding="utf8") as file:
114
- flyout_css = file.read()
115
-
116
- # JavaScript for positioning the flyout panel
117
- head_script = f\"\"\"
118
- <script>
119
- function position_flyout(anchorId) {{
120
- setTimeout(() => {{
121
- const anchorRow = document.getElementById(anchorId).closest('.fake-input-container');
122
- const flyoutElem = document.getElementById('flyout_panel');
123
-
124
- if (anchorRow && flyoutElem && flyoutElem.style.display !== 'none') {{
125
- const anchorRect = anchorRow.getBoundingClientRect();
126
- const containerRect = anchorRow.closest('.flyout-context-area').getBoundingClientRect();
127
-
128
- const flyoutWidth = flyoutElem.offsetWidth;
129
- const flyoutHeight = flyoutElem.offsetHeight;
130
 
131
- const topPosition = (anchorRect.top - containerRect.top) + (anchorRect.height / 2) - (flyoutHeight / 2);
132
- const leftPosition = (anchorRect.left - containerRect.left) + (anchorRect.width / 2) - (flyoutWidth / 2);
 
 
 
 
 
 
 
 
133
 
134
- flyoutElem.style.top = `${{topPosition}}px`;
135
- flyoutElem.style.left = `${{leftPosition}}px`;
136
- }}
137
- }}, 50);
138
- }}
139
- </script>
140
- \"\"\"
141
 
142
  # --- 4. Gradio App Build ---
143
- with gr.Blocks(css=flyout_css, head=head_script, title="PropertySheet Demos") as demo:
 
144
  gr.Markdown("# PropertySheet Component Demos")
145
 
146
  with gr.Tabs():
@@ -302,9 +291,10 @@ with gr.Blocks(css=flyout_css, head=head_script, title="PropertySheet Demos") as
302
  return {
303
  sampler_ear_btn: update_ear_visibility(sampler_val, sampler_settings_map_py),
304
  model_ear_btn: update_ear_visibility(model_val, model_settings_map_py)
305
- }
306
- demo.load(fn=initial_flyout_setup, inputs=[sampler_dd, model_dd], outputs=[sampler_ear_btn, model_ear_btn])
307
-
 
308
  if __name__ == "__main__":
309
  demo.launch()
310
  ```
 
44
  from dataclasses import dataclass, field, asdict
45
  from typing import Literal
46
  from gradio_propertysheet import PropertySheet
47
+ from gradio_headinjector import HeadInjector
48
+
49
 
50
  # --- 1. Dataclass Definitions ---
51
 
 
104
  sampler_settings_map_py = {"Euler": EulerSettings(), "DPM++ 2M Karras": DPM_Settings(), "UniPC": None}
105
  model_settings_map_py = {"SDXL 1.0": DPM_Settings(), "Stable Diffusion 1.5": EulerSettings(), "Pony": None}
106
 
107
+ # --- 3. CSS & JS Injection function ---
108
+
109
+ def inject_assets():
110
+ \"\"\"
111
+ This function prepares the payload of CSS and JS code. It's called by the
112
+ demo.load() event listener when the Gradio app starts.
113
+ \"\"\"
114
+ # Inline code
115
+ css_code = ""
116
+ js_code = ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
+ # Read from files
119
+ try:
120
+ with open("custom.css", "r", encoding="utf-8") as f:
121
+ css_code += f.read() + "\n"
122
+ with open("custom.js", "r", encoding="utf-8") as f:
123
+ js_code += f.read() + "\n"
124
+ except FileNotFoundError as e:
125
+ print(f"Warning: Could not read asset file: {e}")
126
+
127
+ return {"js": js_code, "css": css_code}
128
 
 
 
 
 
 
 
 
129
 
130
  # --- 4. Gradio App Build ---
131
+ with gr.Blocks(title="PropertySheet Demos") as demo:
132
+ head_injector = HeadInjector()
133
  gr.Markdown("# PropertySheet Component Demos")
134
 
135
  with gr.Tabs():
 
291
  return {
292
  sampler_ear_btn: update_ear_visibility(sampler_val, sampler_settings_map_py),
293
  model_ear_btn: update_ear_visibility(model_val, model_settings_map_py)
294
+ }
295
+ demo.load(fn=inject_assets, inputs=None, outputs=[head_injector]
296
+ ).then(fn=initial_flyout_setup, inputs=[sampler_dd, model_dd], outputs=[sampler_ear_btn, model_ear_btn])
297
+
298
  if __name__ == "__main__":
299
  demo.launch()
300
  ```
src/README.md CHANGED
@@ -36,6 +36,7 @@ The **PropertySheet** component for Gradio allows you to automatically generate
36
  - **Theme-Aware**: Designed to look and feel native in all Gradio themes.
37
  - **Dynamic Updates**: Supports advanced patterns where changing one field (e.g., a model selector) can dynamically update the options of another field (e.g., a sampler dropdown).
38
 
 
39
  ## Installation
40
 
41
  ```bash
@@ -51,6 +52,8 @@ import gradio as gr
51
  from dataclasses import dataclass, field, asdict
52
  from typing import Literal
53
  from gradio_propertysheet import PropertySheet
 
 
54
 
55
  # --- 1. Dataclass Definitions ---
56
 
@@ -109,45 +112,32 @@ initial_env_config = EnvironmentConfig()
109
  sampler_settings_map_py = {"Euler": EulerSettings(), "DPM++ 2M Karras": DPM_Settings(), "UniPC": None}
110
  model_settings_map_py = {"SDXL 1.0": DPM_Settings(), "Stable Diffusion 1.5": EulerSettings(), "Pony": None}
111
 
112
- # --- 3. CSS and JavaScript Loading ---
113
-
114
- # Load external CSS file if it exists
115
- script_path = Path(__file__).resolve()
116
- script_dir = script_path.parent
117
- css_path = script_dir / "custom.css"
118
- flyout_css = ""
119
- if css_path.exists():
120
- with open(css_path, "r", encoding="utf8") as file:
121
- flyout_css = file.read()
122
-
123
- # JavaScript for positioning the flyout panel
124
- head_script = f"""
125
- <script>
126
- function position_flyout(anchorId) {{
127
- setTimeout(() => {{
128
- const anchorRow = document.getElementById(anchorId).closest('.fake-input-container');
129
- const flyoutElem = document.getElementById('flyout_panel');
130
-
131
- if (anchorRow && flyoutElem && flyoutElem.style.display !== 'none') {{
132
- const anchorRect = anchorRow.getBoundingClientRect();
133
- const containerRect = anchorRow.closest('.flyout-context-area').getBoundingClientRect();
134
-
135
- const flyoutWidth = flyoutElem.offsetWidth;
136
- const flyoutHeight = flyoutElem.offsetHeight;
137
 
138
- const topPosition = (anchorRect.top - containerRect.top) + (anchorRect.height / 2) - (flyoutHeight / 2);
139
- const leftPosition = (anchorRect.left - containerRect.left) + (anchorRect.width / 2) - (flyoutWidth / 2);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
- flyoutElem.style.top = `${{topPosition}}px`;
142
- flyoutElem.style.left = `${{leftPosition}}px`;
143
- }}
144
- }}, 50);
145
- }}
146
- </script>
147
- """
148
 
149
  # --- 4. Gradio App Build ---
150
- with gr.Blocks(css=flyout_css, head=head_script, title="PropertySheet Demos") as demo:
 
151
  gr.Markdown("# PropertySheet Component Demos")
152
 
153
  with gr.Tabs():
@@ -309,9 +299,10 @@ with gr.Blocks(css=flyout_css, head=head_script, title="PropertySheet Demos") as
309
  return {
310
  sampler_ear_btn: update_ear_visibility(sampler_val, sampler_settings_map_py),
311
  model_ear_btn: update_ear_visibility(model_val, model_settings_map_py)
312
- }
313
- demo.load(fn=initial_flyout_setup, inputs=[sampler_dd, model_dd], outputs=[sampler_ear_btn, model_ear_btn])
314
-
 
315
  if __name__ == "__main__":
316
  demo.launch()
317
  ```
 
36
  - **Theme-Aware**: Designed to look and feel native in all Gradio themes.
37
  - **Dynamic Updates**: Supports advanced patterns where changing one field (e.g., a model selector) can dynamically update the options of another field (e.g., a sampler dropdown).
38
 
39
+
40
  ## Installation
41
 
42
  ```bash
 
52
  from dataclasses import dataclass, field, asdict
53
  from typing import Literal
54
  from gradio_propertysheet import PropertySheet
55
+ from gradio_headinjector import HeadInjector
56
+
57
 
58
  # --- 1. Dataclass Definitions ---
59
 
 
112
  sampler_settings_map_py = {"Euler": EulerSettings(), "DPM++ 2M Karras": DPM_Settings(), "UniPC": None}
113
  model_settings_map_py = {"SDXL 1.0": DPM_Settings(), "Stable Diffusion 1.5": EulerSettings(), "Pony": None}
114
 
115
+ # --- 3. CSS & JS Injection function ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
+ def inject_assets():
118
+ """
119
+ This function prepares the payload of CSS and JS code. It's called by the
120
+ demo.load() event listener when the Gradio app starts.
121
+ """
122
+ # Inline code
123
+ css_code = ""
124
+ js_code = ""
125
+
126
+ # Read from files
127
+ try:
128
+ with open("custom.css", "r", encoding="utf-8") as f:
129
+ css_code += f.read() + "\n"
130
+ with open("custom.js", "r", encoding="utf-8") as f:
131
+ js_code += f.read() + "\n"
132
+ except FileNotFoundError as e:
133
+ print(f"Warning: Could not read asset file: {e}")
134
+
135
+ return {"js": js_code, "css": css_code}
136
 
 
 
 
 
 
 
 
137
 
138
  # --- 4. Gradio App Build ---
139
+ with gr.Blocks(title="PropertySheet Demos") as demo:
140
+ head_injector = HeadInjector()
141
  gr.Markdown("# PropertySheet Component Demos")
142
 
143
  with gr.Tabs():
 
299
  return {
300
  sampler_ear_btn: update_ear_visibility(sampler_val, sampler_settings_map_py),
301
  model_ear_btn: update_ear_visibility(model_val, model_settings_map_py)
302
+ }
303
+ demo.load(fn=inject_assets, inputs=None, outputs=[head_injector]
304
+ ).then(fn=initial_flyout_setup, inputs=[sampler_dd, model_dd], outputs=[sampler_ear_btn, model_ear_btn])
305
+
306
  if __name__ == "__main__":
307
  demo.launch()
308
  ```
src/demo/app.py CHANGED
@@ -6,25 +6,6 @@ from typing import Literal
6
  from gradio_propertysheet import PropertySheet
7
  from gradio_headinjector import HeadInjector
8
 
9
- def inject_assets():
10
- """
11
- This function prepares the payload of CSS and JS code. It's called by the
12
- demo.load() event listener when the Gradio app starts.
13
- """
14
- # Inline code
15
- css_code = ""
16
- js_code = ""
17
-
18
- # Read from files
19
- try:
20
- with open("custom.css", "r", encoding="utf-8") as f:
21
- css_code += f.read() + "\n"
22
- with open("custom.js", "r", encoding="utf-8") as f:
23
- js_code += f.read() + "\n"
24
- except FileNotFoundError as e:
25
- print(f"Warning: Could not read asset file: {e}")
26
-
27
- return {"js": js_code, "css": css_code}
28
 
29
  # --- 1. Dataclass Definitions ---
30
 
@@ -83,42 +64,28 @@ initial_env_config = EnvironmentConfig()
83
  sampler_settings_map_py = {"Euler": EulerSettings(), "DPM++ 2M Karras": DPM_Settings(), "UniPC": None}
84
  model_settings_map_py = {"SDXL 1.0": DPM_Settings(), "Stable Diffusion 1.5": EulerSettings(), "Pony": None}
85
 
86
- # --- 3. CSS and JavaScript Loading ---
87
 
88
- # Load external CSS file if it exists
89
- # script_path = Path(__file__).resolve()
90
- # script_dir = script_path.parent
91
- # css_path = script_dir / "custom.css"
92
- # flyout_css = ""
93
- # if css_path.exists():
94
- # with open(css_path, "r", encoding="utf8") as file:
95
- # flyout_css = file.read()
96
 
97
- # JavaScript for positioning the flyout panel
98
- # head_script = f"""
99
- # <script>
100
- # function position_flyout(anchorId) {{
101
- # setTimeout(() => {{
102
- # const anchorRow = document.getElementById(anchorId).closest('.fake-input-container');
103
- # const flyoutElem = document.getElementById('flyout_panel');
104
-
105
- # if (anchorRow && flyoutElem && flyoutElem.style.display !== 'none') {{
106
- # const anchorRect = anchorRow.getBoundingClientRect();
107
- # const containerRect = anchorRow.closest('.flyout-context-area').getBoundingClientRect();
108
-
109
- # const flyoutWidth = flyoutElem.offsetWidth;
110
- # const flyoutHeight = flyoutElem.offsetHeight;
111
 
112
- # const topPosition = (anchorRect.top - containerRect.top) + (anchorRect.height / 2) - (flyoutHeight / 2);
113
- # const leftPosition = (anchorRect.left - containerRect.left) + (anchorRect.width / 2) - (flyoutWidth / 2);
114
 
115
- # flyoutElem.style.top = `${{topPosition}}px`;
116
- # flyoutElem.style.left = `${{leftPosition}}px`;
117
- # }}
118
- # }}, 50);
119
- # }}
120
- # </script>
121
- # # """
122
 
123
  # --- 4. Gradio App Build ---
124
  with gr.Blocks(title="PropertySheet Demos") as demo:
@@ -285,7 +252,8 @@ with gr.Blocks(title="PropertySheet Demos") as demo:
285
  sampler_ear_btn: update_ear_visibility(sampler_val, sampler_settings_map_py),
286
  model_ear_btn: update_ear_visibility(model_val, model_settings_map_py)
287
  }
288
- demo.load(fn=inject_assets, inputs=None, outputs=[head_injector]).then(fn=initial_flyout_setup, inputs=[sampler_dd, model_dd], outputs=[sampler_ear_btn, model_ear_btn])
 
289
 
290
  if __name__ == "__main__":
291
  demo.launch()
 
6
  from gradio_propertysheet import PropertySheet
7
  from gradio_headinjector import HeadInjector
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # --- 1. Dataclass Definitions ---
11
 
 
64
  sampler_settings_map_py = {"Euler": EulerSettings(), "DPM++ 2M Karras": DPM_Settings(), "UniPC": None}
65
  model_settings_map_py = {"SDXL 1.0": DPM_Settings(), "Stable Diffusion 1.5": EulerSettings(), "Pony": None}
66
 
67
+ # --- 3. CSS & JS Injection function ---
68
 
69
+ def inject_assets():
70
+ """
71
+ This function prepares the payload of CSS and JS code. It's called by the
72
+ demo.load() event listener when the Gradio app starts.
73
+ """
74
+ # Inline code
75
+ css_code = ""
76
+ js_code = ""
77
 
78
+ # Read from files
79
+ try:
80
+ with open("custom.css", "r", encoding="utf-8") as f:
81
+ css_code += f.read() + "\n"
82
+ with open("custom.js", "r", encoding="utf-8") as f:
83
+ js_code += f.read() + "\n"
84
+ except FileNotFoundError as e:
85
+ print(f"Warning: Could not read asset file: {e}")
 
 
 
 
 
 
86
 
87
+ return {"js": js_code, "css": css_code}
 
88
 
 
 
 
 
 
 
 
89
 
90
  # --- 4. Gradio App Build ---
91
  with gr.Blocks(title="PropertySheet Demos") as demo:
 
252
  sampler_ear_btn: update_ear_visibility(sampler_val, sampler_settings_map_py),
253
  model_ear_btn: update_ear_visibility(model_val, model_settings_map_py)
254
  }
255
+ demo.load(fn=inject_assets, inputs=None, outputs=[head_injector]
256
+ ).then(fn=initial_flyout_setup, inputs=[sampler_dd, model_dd], outputs=[sampler_ear_btn, model_ear_btn])
257
 
258
  if __name__ == "__main__":
259
  demo.launch()
src/demo/space.py CHANGED
@@ -44,6 +44,8 @@ import gradio as gr
44
  from dataclasses import dataclass, field, asdict
45
  from typing import Literal
46
  from gradio_propertysheet import PropertySheet
 
 
47
 
48
  # --- 1. Dataclass Definitions ---
49
 
@@ -102,45 +104,32 @@ initial_env_config = EnvironmentConfig()
102
  sampler_settings_map_py = {"Euler": EulerSettings(), "DPM++ 2M Karras": DPM_Settings(), "UniPC": None}
103
  model_settings_map_py = {"SDXL 1.0": DPM_Settings(), "Stable Diffusion 1.5": EulerSettings(), "Pony": None}
104
 
105
- # --- 3. CSS and JavaScript Loading ---
106
-
107
- # Load external CSS file if it exists
108
- script_path = Path(__file__).resolve()
109
- script_dir = script_path.parent
110
- css_path = script_dir / "custom.css"
111
- flyout_css = ""
112
- if css_path.exists():
113
- with open(css_path, "r", encoding="utf8") as file:
114
- flyout_css = file.read()
115
-
116
- # JavaScript for positioning the flyout panel
117
- head_script = f\"\"\"
118
- <script>
119
- function position_flyout(anchorId) {{
120
- setTimeout(() => {{
121
- const anchorRow = document.getElementById(anchorId).closest('.fake-input-container');
122
- const flyoutElem = document.getElementById('flyout_panel');
123
-
124
- if (anchorRow && flyoutElem && flyoutElem.style.display !== 'none') {{
125
- const anchorRect = anchorRow.getBoundingClientRect();
126
- const containerRect = anchorRow.closest('.flyout-context-area').getBoundingClientRect();
127
-
128
- const flyoutWidth = flyoutElem.offsetWidth;
129
- const flyoutHeight = flyoutElem.offsetHeight;
130
 
131
- const topPosition = (anchorRect.top - containerRect.top) + (anchorRect.height / 2) - (flyoutHeight / 2);
132
- const leftPosition = (anchorRect.left - containerRect.left) + (anchorRect.width / 2) - (flyoutWidth / 2);
 
 
 
 
 
 
 
 
133
 
134
- flyoutElem.style.top = `${{topPosition}}px`;
135
- flyoutElem.style.left = `${{leftPosition}}px`;
136
- }}
137
- }}, 50);
138
- }}
139
- </script>
140
- \"\"\"
141
 
142
  # --- 4. Gradio App Build ---
143
- with gr.Blocks(css=flyout_css, head=head_script, title="PropertySheet Demos") as demo:
 
144
  gr.Markdown("# PropertySheet Component Demos")
145
 
146
  with gr.Tabs():
@@ -302,9 +291,10 @@ with gr.Blocks(css=flyout_css, head=head_script, title="PropertySheet Demos") as
302
  return {
303
  sampler_ear_btn: update_ear_visibility(sampler_val, sampler_settings_map_py),
304
  model_ear_btn: update_ear_visibility(model_val, model_settings_map_py)
305
- }
306
- demo.load(fn=initial_flyout_setup, inputs=[sampler_dd, model_dd], outputs=[sampler_ear_btn, model_ear_btn])
307
-
 
308
  if __name__ == "__main__":
309
  demo.launch()
310
  ```
 
44
  from dataclasses import dataclass, field, asdict
45
  from typing import Literal
46
  from gradio_propertysheet import PropertySheet
47
+ from gradio_headinjector import HeadInjector
48
+
49
 
50
  # --- 1. Dataclass Definitions ---
51
 
 
104
  sampler_settings_map_py = {"Euler": EulerSettings(), "DPM++ 2M Karras": DPM_Settings(), "UniPC": None}
105
  model_settings_map_py = {"SDXL 1.0": DPM_Settings(), "Stable Diffusion 1.5": EulerSettings(), "Pony": None}
106
 
107
+ # --- 3. CSS & JS Injection function ---
108
+
109
+ def inject_assets():
110
+ \"\"\"
111
+ This function prepares the payload of CSS and JS code. It's called by the
112
+ demo.load() event listener when the Gradio app starts.
113
+ \"\"\"
114
+ # Inline code
115
+ css_code = ""
116
+ js_code = ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
+ # Read from files
119
+ try:
120
+ with open("custom.css", "r", encoding="utf-8") as f:
121
+ css_code += f.read() + "\n"
122
+ with open("custom.js", "r", encoding="utf-8") as f:
123
+ js_code += f.read() + "\n"
124
+ except FileNotFoundError as e:
125
+ print(f"Warning: Could not read asset file: {e}")
126
+
127
+ return {"js": js_code, "css": css_code}
128
 
 
 
 
 
 
 
 
129
 
130
  # --- 4. Gradio App Build ---
131
+ with gr.Blocks(title="PropertySheet Demos") as demo:
132
+ head_injector = HeadInjector()
133
  gr.Markdown("# PropertySheet Component Demos")
134
 
135
  with gr.Tabs():
 
291
  return {
292
  sampler_ear_btn: update_ear_visibility(sampler_val, sampler_settings_map_py),
293
  model_ear_btn: update_ear_visibility(model_val, model_settings_map_py)
294
+ }
295
+ demo.load(fn=inject_assets, inputs=None, outputs=[head_injector]
296
+ ).then(fn=initial_flyout_setup, inputs=[sampler_dd, model_dd], outputs=[sampler_ear_btn, model_ear_btn])
297
+
298
  if __name__ == "__main__":
299
  demo.launch()
300
  ```