This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import gradio as gr | |
| def infer(*args): | |
| # ... | |
| return "done" | |
| css = """ | |
| div#col-container{ | |
| margin: 0 auto; | |
| max-width: 800px; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from moviepy.editor import VideoFileClip | |
| import os | |
| def convert_video_to_h264_aac(video_path): | |
| # Get the directory and original filename | |
| original_dir = os.path.dirname(video_path) | |
| original_name, _ = os.path.splitext(os.path.basename(video_path)) | |
| # Define the output path in the same directory | |
| output_path = os.path.join(original_dir, f"{original_name}_converted.mp4") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let img_result; | |
| let img_to_download; | |
| function blobToGraphics(buffer){ | |
| // Create a blob from the buffer response | |
| let myBlob = new Blob([buffer], {type: "image/png"}); | |
| console.log(myBlob); | |
| let uri = URL.createObjectURL(myBlob); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function graphicsToBlob(){ | |
| //for canvas | |
| let image64 = canvas.elt.toDataURL('image/png'); | |
| //for graphics | |
| sourceGraphics.loadPixels(); | |
| let image64 = sourceGraphics.canvas.toDataURL('image/png'); | |
| fetch(img_data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Resizing the canvas is simple | |
| resizeCanvas(new_width, new_height) | |
| // Resizing graphics is tricky | |
| function resizeGraphics(new_width, new_height, old_graphics){ | |
| let new_graphics = createGraphics(new_width, new_height); | |
| new_graphics.image(old_graphics, 0, 0, new_width, new_height); | |
| return new_graphics; | |
| } | |
| //then call it directly to switch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let canvas; | |
| let pointerX = 0; | |
| let pointerY = 0; | |
| let isOnCanvas = false; | |
| let inclinationX = 0; | |
| let inclinationY = 0; | |
| let pressure = 0; | |
| let diameter = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let peaks = []; | |
| let rectRadius = 4; | |
| let barsW = 3; | |
| let soundFile = loadSound('path/to/audio.mp3'); // loadSound() is a p5sound method | |
| // loadSound inside the preload() function | |
| // We calculate audio peaks to show bars and wave | |
| // Do this inside setup() function | |
| peaks = soundFile.getPeaks(width/(barsW*2)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // HTML index.html | |
| // <div id="myCanvasContainer"></div> | |
| // JS sketch.js | |
| // Inside setup() function | |
| let canvasDiv = document.getElementById('myCanvasContainer'); | |
| let width = canvasDiv.offsetWidth; | |
| let height = canvasDiv.offsetHeight; | |
| let sketchCanvas = createCanvas(width,height); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| new Date(seconds * 1000).toISOString().substr(11, 8) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ES2015 | |
| function zeroPad(num, places) { | |
| var zero = places - num.toString().length + 1; | |
| return Array(+(zero > 0 && zero)).join("0") + num; | |
| } | |
| zeroPad(5, 2); // "05" | |
| zeroPad(5, 4); // "0005" | |
| zeroPad(5, 6); // "000005" |