Commit ·
fa56cd0
1
Parent(s): 7c62b94
Self-contained app.py with HF model download
Browse files2 unmodified lines3456789101112135 unmodified lines1920212223242526272829302 unmodified linesfrom __future__ import annotationsimport osimport gradio as grimport numpy as npfrom model.pico_type.labels import ALL_HEADS, COARSE_LABELS, MODALITY_LABELS, SUBTYPE_LABELS, CODE_LANG_LABELS, TEXT_LANG_LABELS, FILE_MIME_LABELS, RISK_LABELSLABEL_TABLES = {"coarse": COARSE_LABELS,5 unmodified lines"risk": RISK_LABELS,}MODEL_DIR = os.environ.get("PICOTYPE_MODEL_DIR", "checkpoints")def _load_session(tier: str):import onnxruntime as ortpath = os.path.join(MODEL_DIR, f"picotype_{tier}.onnx")return ort.InferenceSession(path)2 unmodified lines345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182835 unmodified lines89909192939495969798991001011021031041051061071081091101112 unmodified linesfrom __future__ import annotationsimport osfrom pathlib import Pathimport gradio as grimport numpy as npALL_HEADS = ("coarse", "modality", "subtype", "code_lang", "text_lang", "file_mime", "risk")COARSE_LABELS = ["text", "code", "link", "image", "file", "config","markup", "data", "error", "secret", "archive", "binary",]MODALITY_LABELS = ["textual", "binary_image", "binary_archive", "binary_executable","binary_document", "binary_audio", "binary_video", "binary_other",]SUBTYPE_LABELS = ["json", "yaml", "toml", "ini", "csv", "tsv", "xml","html", "markdown", "rst", "asciidoc", "tex","sql", "graphql", "protobuf", "msgpack","log", "diff", "patch", "env","shell", "makefile", "dockerfile", "gitignore",]CODE_LANG_LABELS = ["python", "javascript", "typescript", "jsx", "tsx","java", "kotlin", "scala", "groovy", "clojure","c", "cpp", "csharp", "fsharp", "objectivec","go", "rust", "zig","ruby", "php", "perl", "lua", "tcl","swift", "dart", "julia", "nim", "crystal","haskell", "ocaml", "elm", "erlang", "elixir","lisp", "scheme", "racket","r", "matlab", "octave", "sas", "stata","sql", "plsql", "tsql","html", "css", "scss", "sass", "less","bash", "zsh", "fish", "powershell","vim", "fortran", "cobol", "ada", "pascal","delphi", "vb", "prolog", "vhdl",]TEXT_LANG_LABELS = ["en", "es", "fr", "de", "it", "pt", "nl", "sv", "no", "da","fi", "pl", "cs", "sk", "hu", "ro", "el", "tr","ru", "uk", "bg", "sr", "hr","zh", "ja", "ko", "ar", "hi", "th", "vi",]FILE_MIME_LABELS = ["text/html", "application/json", "application/xml", "text/yaml","text/toml", "text/ini", "text/csv", "text/tsv", "text/markdown","text/plain", "text/x-python", "text/x-java", "text/x-c","text/x-cpp", "text/x-rust", "text/x-go", "text/x-ruby","text/x-php", "text/x-javascript", "text/x-typescript","text/x-shellscript", "text/x-sql", "text/x-dockerfile","text/x-makefile", "text/x-yaml", "text/x-diff", "text/x-log","text/x-env", "text/x-tex", "text/x-asciidoc", "text/x-rst","application/pdf", "application/zip", "application/gzip","application/x-tar", "application/x-7z-compressed", "application/x-rar-compressed","application/x-bzip2", "application/x-xz", "application/x-iso9660-image","application/vnd.sqlite3", "application/x-parquet","application/x-elf", "application/x-mach-binary","application/x-pe-executable", "application/java-archive","application/wasm", "application/vnd.debian.binary-package","application/x-apple-diskimage", "application/x-msdownload","application/x-sharedlib", "application/x-object","application/x-pcap", "application/x-hdf5", "application/x-netcdf","application/xml", "application/atom+xml", "application/rss+xml","application/rdf+xml", "application/xhtml+xml","image/png", "image/jpeg", "image/gif", "image/webp", "image/bmp","image/tiff", "image/svg+xml", "image/x-icon", "image/avif","audio/mpeg", "audio/wav", "audio/ogg", "audio/flac","audio/aac", "audio/mp4", "audio/webm","video/mp4", "video/webm", "video/ogg", "video/x-msvideo","video/quicktime", "video/x-matroska","font/ttf", "font/otf", "font/woff", "font/woff2","application/octet-stream", "application/unknown",]RISK_LABELS = ["api_key", "jwt", "ssh_key", "password", "email", "phone"]LABEL_TABLES = {"coarse": COARSE_LABELS,5 unmodified lines"risk": RISK_LABELS,}MODEL_DIR = "."def _ensure_onnx(tier: str):path = os.path.join(MODEL_DIR, f"picotype_{tier}.onnx")if not os.path.exists(path):from huggingface_hub import hf_hub_downloadfor t in ["tiny", "small", "base", "pro"]:fname = f"picotype_{t}.onnx"hf_hub_download("eulogik/pico-type", filename=fname, local_dir=MODEL_DIR)hf_hub_download("eulogik/pico-type", filename=f"{fname}.data", local_dir=MODEL_DIR)return pathdef _load_session(tier: str):import onnxruntime as ortpath = _ensure_onnx(tier)return ort.InferenceSession(path)
app.py+84-3