Skip to content

Instantly share code, notes, and snippets.

View mahiya's full-sized avatar

Masayuki Hiyama mahiya

  • Microsoft
  • Tokyo
View GitHub Profile
@mahiya
mahiya / document_intelligence.py
Last active June 10, 2024 05:52
旧 Azure Document Intelligence SDK の使い方
# pip install azure-ai-formrecognizer==3.3.0
import json
from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import DocumentAnalysisClient
# Azure Document Intelligence のエンドポイントとキーを設定
endpoint = "https://xxx.cognitiveservices.azure.com/"
key = ""
# 処理対象の PDF ファイルのパスを設定
@mahiya
mahiya / prompty_sample.py
Created June 1, 2024 14:16
Prompty で GPT4 with Vision を使う方法
from promptflow.core import Prompty
from promptflow.contracts.multimedia import PFBytes
image_urls = [
"画像にアクセスすることができるURL(SAS付きURLとか)",
]
images = [PFBytes(bytes(image_url, "utf-8"), "image/jpeg", source_url=image_url) for image_url in image_urls]
image_paths = [str(image) for image in images]
f = Prompty.load(source="sample.prompty")
import os
import json
import requests
class ImageEmbeddingsClient:
def __init__(self, computer_vision_endpoint: str = None, computer_vision_key: str = None,):
self.endpoint = computer_vision_endpoint if computer_vision_endpoint else os.getenv("AZURE_COMPUTER_VISION_ENDPOINT")
self.key = computer_vision_key if computer_vision_key else os.getenv("AZURE_COMPUTER_VISION_KEY")
@mahiya
mahiya / app.py
Created January 31, 2024 00:40
マルチスレッドで Azure OpenAI Service の Embeddings API を呼び出して埋め込みを取得する処理 (Python)
from utilities.parallel_embeddings import ParallelEmbeddingsClient
client = ParallelEmbeddingsClient("embeddings_config.json")
texts = [ f"埋め込みを取得する対象のテキスト" for i in range(0, 10) ]
embeds = client.get_embeds(texts)
@mahiya
mahiya / analyze-text.py
Created December 13, 2023 06:12
Python で Azure AI Search の Analyze Text API を使用するコード
# https://learn.microsoft.com/ja-jp/rest/api/searchservice/test-analyzer
import os, sys, json, requests
search_name = os.environ["AZURE_SEARCH_NAME"]
index_name = os.environ["AZURE_SEARCH_INDEX_NAME"]
api_key = os.environ["AZURE_SEARCH_KEY"]
api_version = "2020-06-30"
target_analyzer_name = "ja.microsoft"
target_analyze_text = "Azure AI Search は、従来の会話型検索アプリケーションのユーザー所有コンテンツに対して、安全な情報取得を大規模に提供します。"
@mahiya
mahiya / CognitiveSearchClient.cs
Created December 7, 2023 23:51
C# で Azure AI Search にインデックスを作成して、そこにドキュメントを登録するコード
// dotnet add package Azure.Search.Documents
using Azure;
using Azure.Search.Documents;
using Azure.Search.Documents.Indexes;
using Azure.Search.Documents.Indexes.Models;
using Azure.Search.Documents.Models;
namespace SearchIndexCreator
{
class CognitiveSearchClient
@mahiya
mahiya / index.html
Created December 1, 2023 08:05
JavaScript で Azure AI Speech でリアルタイム文字起こしを行うコード
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-scale=1.0, user-scalable=no">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
* {
@mahiya
mahiya / RealtimeAudioRecognitionByAzure.cs
Created December 1, 2023 07:41
Azure AI Speech でリアルタイム音声認識を行うコード
// dotnet add package Microsoft.CognitiveServices.Speech --version 1.33.0
// dotnet add package NAudio --version 2.2.1
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
using NAudio.CoreAudioApi;
namespace RealtimeAudioRecognitionByAzure
{
class Program
{
@mahiya
mahiya / RecordFromMicAndAudio.cs
Created December 1, 2023 05:11
C# でオーディオデバイスやマイクデバイスからその入出力を録音してファイル出力する処理
// dotnet add package NAudio --version 2.2.1
using NAudio.CoreAudioApi;
using NAudio.Wave;
namespace RecordFromMicAndAudio
{
class Program
{
static void Main()
{
@mahiya
mahiya / computer_vision_account.json
Last active September 14, 2023 01:41
Azure AI Vision - Vectorize Image API を使って画像をベクトル化する処理 (Python)
{
"endpoint": "https://xxxxx.cognitiveservices.azure.com/",
"key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}