Spaces:
Runtime error
Runtime error
shadertoy iframe
Browse files
app.py
CHANGED
@@ -139,6 +139,13 @@ text = """
|
|
139 |
This gives you access to a filtered version of the [Shadertoys](https://huggingface.co/datasets/Vipitis/Shadertoys) dataset, only shaders that const of a single pass (and have at least one fuction with a return statement) are available.
|
140 |
In the near future there will be some buttons and sliders to generate variations of the shadercode itself, and hence get some different images.
|
141 |
If I find an efficient way, the shaders might run in real time and be interactive.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
"""
|
143 |
passes_dataset = datasets.load_dataset("Vipitis/Shadertoys")
|
144 |
single_passes = passes_dataset.filter(lambda x: not x["has_inputs"] and x["num_passes"] == 1 and x["code"].count("return") >= 1) #filter easier than having a custom loader script?
|
@@ -162,13 +169,17 @@ def grab_sample(sample_idx):
|
|
162 |
sample_source = sample_pass["source"]
|
163 |
sample_title = sample_pass["title"]
|
164 |
sample_auhtor = sample_pass["author"]
|
165 |
-
|
|
|
166 |
|
167 |
def _make_pipeline(model_cp):
|
168 |
tokenizer = AutoTokenizer.from_pretrained(model_cp, trust_remote_code=True)
|
169 |
model = AutoModelForCausalLM.from_pretrained(model_cp, trust_remote_code=True)
|
170 |
return pipeline("text-generation", model=model, tokenizer=tokenizer, trust_remote_code=True)
|
171 |
|
|
|
|
|
|
|
172 |
with gr.Blocks() as site:
|
173 |
text_md = gr.Markdown(text)
|
174 |
model_cp = gr.Textbox(value="Vipitis/santacoder-finetuned-Shadertoys", label="Model Checkpoint", interactive=True)
|
@@ -178,10 +189,12 @@ with gr.Blocks() as site:
|
|
178 |
time_slider = gr.Slider(minimum=0, maximum=10, value=0, label="time (update on release)", step=0.02)
|
179 |
#output = gr.Textbox(label="Output")
|
180 |
rendered_frame = gr.Image(shape=(512, 420), label=f"rendered frame preview")
|
181 |
-
info_md = gr.Markdown(value="code_source", label="source URL for this shader", interactive=False)
|
|
|
182 |
sample_code = gr.Code(label="Sample Code", language=None, readonly=True, lines=20)
|
183 |
-
sample_pass = gr.State(value=
|
184 |
-
sample_idx.release(fn=grab_sample, inputs=[sample_idx], outputs=[sample_code,
|
|
|
185 |
time_slider.release(fn=lambda code, time: asyncio.run(get_image(code, time)), inputs=[sample_code, time_slider], outputs=rendered_frame)
|
186 |
render_button.click(fn=lambda code: asyncio.run(get_image(code)), inputs=[sample_code], outputs=rendered_frame)
|
187 |
# run_button.click(fn=print, inputs=[model_cp, sample_idx], outputs=output)
|
|
|
139 |
This gives you access to a filtered version of the [Shadertoys](https://huggingface.co/datasets/Vipitis/Shadertoys) dataset, only shaders that const of a single pass (and have at least one fuction with a return statement) are available.
|
140 |
In the near future there will be some buttons and sliders to generate variations of the shadercode itself, and hence get some different images.
|
141 |
If I find an efficient way, the shaders might run in real time and be interactive.
|
142 |
+
|
143 |
+
## TODO:
|
144 |
+
- [~] use embedded Shadertoy for reference/attribution (seems to not on change??)
|
145 |
+
- [] working render implementation on CPU only space (use the browser for WebGPU?)
|
146 |
+
- [] generate variations of return statements (ShaderEval task1)
|
147 |
+
- [] generate whole functions
|
148 |
+
- [] generate whole shaders (via prompts?)
|
149 |
"""
|
150 |
passes_dataset = datasets.load_dataset("Vipitis/Shadertoys")
|
151 |
single_passes = passes_dataset.filter(lambda x: not x["has_inputs"] and x["num_passes"] == 1 and x["code"].count("return") >= 1) #filter easier than having a custom loader script?
|
|
|
169 |
sample_source = sample_pass["source"]
|
170 |
sample_title = sample_pass["title"]
|
171 |
sample_auhtor = sample_pass["author"]
|
172 |
+
source_iframe = construct_embed(sample_source)
|
173 |
+
return sample_pass, sample_code, source_iframe #, sample_title, sample_auhtor
|
174 |
|
175 |
def _make_pipeline(model_cp):
|
176 |
tokenizer = AutoTokenizer.from_pretrained(model_cp, trust_remote_code=True)
|
177 |
model = AutoModelForCausalLM.from_pretrained(model_cp, trust_remote_code=True)
|
178 |
return pipeline("text-generation", model=model, tokenizer=tokenizer, trust_remote_code=True)
|
179 |
|
180 |
+
def construct_embed(source_url):
|
181 |
+
return f'<iframe width="640" height="360" frameborder="0" src="{source_url}?gui=true&t=0&paused=true&muted=true" allowfullscreen></iframe>'
|
182 |
+
|
183 |
with gr.Blocks() as site:
|
184 |
text_md = gr.Markdown(text)
|
185 |
model_cp = gr.Textbox(value="Vipitis/santacoder-finetuned-Shadertoys", label="Model Checkpoint", interactive=True)
|
|
|
189 |
time_slider = gr.Slider(minimum=0, maximum=10, value=0, label="time (update on release)", step=0.02)
|
190 |
#output = gr.Textbox(label="Output")
|
191 |
rendered_frame = gr.Image(shape=(512, 420), label=f"rendered frame preview")
|
192 |
+
# info_md = gr.Markdown(value="code_source", label="source URL for this shader", interactive=False)
|
193 |
+
source_embed = gr.HTML('<iframe width="640" height="360" frameborder="0" src="https://www.shadertoy.com/embed/XtcSDf?gui=true&t=0&paused=true&muted=true" allowfullscreen></iframe>')
|
194 |
sample_code = gr.Code(label="Sample Code", language=None, readonly=True, lines=20)
|
195 |
+
sample_pass = gr.State(value={})
|
196 |
+
sample_idx.release(fn=grab_sample, inputs=[sample_idx], outputs=[sample_pass, sample_code, source_embed])
|
197 |
+
# sample_idx.release(fn=construct_embed, inputs=[sample_idx], outputs=[source_embed]) #twice to make have different outputs?
|
198 |
time_slider.release(fn=lambda code, time: asyncio.run(get_image(code, time)), inputs=[sample_code, time_slider], outputs=rendered_frame)
|
199 |
render_button.click(fn=lambda code: asyncio.run(get_image(code)), inputs=[sample_code], outputs=rendered_frame)
|
200 |
# run_button.click(fn=print, inputs=[model_cp, sample_idx], outputs=output)
|