Skip to content

Instantly share code, notes, and snippets.

@jkone27
Created January 20, 2025 14:07
Show Gist options
  • Save jkone27/27f4278fbc4b5d7120c48f7543b8cc35 to your computer and use it in GitHub Desktop.
Save jkone27/27f4278fbc4b5d7120c48f7543b8cc35 to your computer and use it in GitHub Desktop.
file downloader F#
#r "nuget: Microsoft.ML"
#r "nuget: Microsoft.ML.OnnxTransformer"
#r "nuget: System.Net.Http"
#r "nuget: Downloader"
// Import required namespaces
open System
open Downloader
let downloadFileWithProgress (destinationPath: string) (url: string) =
let config = DownloadConfiguration(
ParallelDownload = true,
ChunkCount = 10
)
let downloader = new DownloadService(config)
let rnd = new Random()
// Register event handlers for progress reporting
downloader.DownloadProgressChanged.Add(fun args ->
if args.ProgressPercentage = 100. || rnd.Next(200) = 1 then
printfn "Progress: %.2f, Speed: %f KB/s, Transferred: %d MB, Total: %d MB"
args.ProgressPercentage
(args.BytesPerSecondSpeed / 1024.0)
(args.ReceivedBytes.Length / (1024 * 1024))
(args.TotalBytesToReceive / (1024L * 1024L))
)
downloader.DownloadFileTaskAsync(url, destinationPath)
// Example usage
let test () =
"https://huggingface.co/onnx-community/Phi-3.5-mini-instruct-onnx-web/resolve/main/onnx/model_q4f16.onnx"
|> downloadFileWithProgress "./downloaded_test.onnx"
|> Async.AwaitTask
|> Async.RunSynchronously
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment