Skip to content

Instantly share code, notes, and snippets.

View 7effrey89's full-sized avatar

Jeffrey Lai 7effrey89

  • Microsoft
  • Denmark
View GitHub Profile
@7effrey89
7effrey89 / Program.cs
Created July 9, 2025 08:24
C# Azure AI Translation - Batch Translate files
using Azure;
using Azure.AI.Translation.Document;
/// <summary>
/// This program demonstrates how to use Azure's Document Translation service to translate documents
/// stored in an Azure Blob Storage container from one language to another.
/// It authenticates using a custom endpoint and resource key, then submits a translation job,
/// waits for completion, and prints the status and results for each document.
/// https://learn.microsoft.com/en-us/azure/ai-services/translator/document-translation/how-to-guides/use-rest-api-programmatically?tabs=csharp
/// https://learn.microsoft.com/en-us/dotnet/api/overview/azure/ai.translation.document-readme?view=azure-dotnet
@7effrey89
7effrey89 / app.py
Last active July 9, 2025 08:26
python - Remove embedded ocr text in pdf, and apply a new layer of ocr text using document intelligence
# Script to create searchable PDF from scan PDF or images using Azure Form Recognizer / Document Intelligence
#
# USAGE:
# python Untitled-1.py <input_file> [-o <output_file>]
#
# ARGUMENTS:
# <input_file> Path to your PDF or image file (jpg, jpeg, tif, tiff, bmp, png).
# -o <output_file> (optional) Name for the output searchable PDF.
# If omitted, output will be <input_file>.ocr.pdf
#
@7effrey89
7effrey89 / app.py
Created May 21, 2025 12:02
Connect and opens a blob on ADLS Gen2 using a service principal
from azure.storage.filedatalake import DataLakeServiceClient
from azure.identity import ClientSecretCredential
# Service principal credentials
app = "<app Registration Name>" # App Registration Name
tenant_id = '<tenant_id>' # Directory (tenant) ID
client_id = '<client_id>' # Application (client) ID
client_secret = '<client_secret>' # Client secret
# Storage account name
@7effrey89
7effrey89 / Pipeline_Execute_ADF_Pipeline.yaml
Last active March 21, 2025 10:24
Azure DevOps Pipeline to Execute Azure Data Factory Pipeline using REST API
trigger:
branches:
include:
- main
variables:
resourceGroupName: '<Name of Resource Group>' # My Resource Group Name
dataFactoryName: '<Name of ADF instance>' # My Data Factory Name
pipelineName: '<Name of Pipeline>' # My Data Factory Pipeline Name
@7effrey89
7effrey89 / Pipeline_Execute_Fabric_Pipeline.yaml
Last active March 21, 2025 10:24
Azure DevOps Pipeline to Execute Microsoft Fabric Pipeline using REST API
trigger:
branches:
include:
- main
variables:
pWorkspaceId: '<GUID OF FABRIC WORKSPACE>' #My Fabric Workspace ID
pPipelineId: '<GUID OF FABRIC PIPELINE IN WORKSPACE>' #My Fabric Pipeline ID
stages:
@7effrey89
7effrey89 / aml_fabric.py
Last active March 11, 2025 14:38
AML integration with Microsoft Fabric
# %%
!pip install mltable
# %%
# AML to query delta table in lakehouse to pandas dataframe
from mltable import from_delta_lake
#url = "https://onelake.dfs.fabric.microsoft.com/ws_ramboll_data/bronze.Lakehouse/Tables/taxidatacsv"
abfs = "abfss://ws_ramboll_data@onelake.dfs.fabric.microsoft.com/bronze.Lakehouse/Tables/taxidatacsv"
df2 = from_delta_lake(abfs).to_pandas_dataframe()
@7effrey89
7effrey89 / Notebook.ipynb
Last active March 7, 2025 09:12
Microsoft Fabric - Notebook Ai Functions
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@7effrey89
7effrey89 / app.py
Created October 29, 2024 10:38
GPT4o/mini translation sample that translate an input and calculates the costs based on Sweden Central
import os
import requests
import json
################################## Facts ######################################################
#GPT costs for GPT-4o and GPT-4o-Mini for Sweden Central per 1000 tokens
#https://azure.microsoft.com/en-us/pricing/calculator
GPT4O_GLOBAL_DEPLOYMENT_INPUT = 0.0025
GPT4O_GLOBAL_DEPLOYMENT_OUTPUT = 0.0100
@7effrey89
7effrey89 / app.py
Last active September 3, 2024 19:28
Azure Document Translation using Access Token Authentication
# Pre-requisites:
# 1. Create a service princple in Azure AD
# 2. Create a new client secret for it (note down the client-id, tenant-id, and secret-value)
# 3. Go to the Azure portal and find the Translator service among the Azure AI Services.
# 4. In the Access Control (IAM) tab, assign the service principle the "Cognitive Services User" role
# 5. In the Resource management tab, enable a System assigned Identity.
# 6. under Azure Role Assignment, choose scope: Storage, Resource: your blob storage (where your documents reside), Role: "Storage Blob Data Contributor"
# 7- Run the code below to get the service to translate all documents in one container to another container
from azure.core.credentials import AccessToken, AzureKeyCredential, TokenCredential
@7effrey89
7effrey89 / Sharepoint_web_Scraper.py
Last active September 20, 2024 10:33
Python web automation using Selenium and Edge to interact and print sharepoint webpage.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options as EdgeOptions
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#selenium 4.23.1 was used for this code
#edge browser: Version 127.0.2651.105 (Official build) (64-bit)
#edge driver: Version 127.0.2651.105 (Stable Channel) (64-bit)