generated from ks6088ts/template-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from ks6088ts-labs/feature/issue-38_refactor-envs
refactor codes
- Loading branch information
Showing
57 changed files
with
1,962 additions
and
276 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
AZURE_AI_DOCUMENT_INTELLIGENCE_ENDPOINT="https://<your-document-intelligence-name>.cognitiveservices.azure.com" | ||
AZURE_AI_DOCUMENT_INTELLIGENCE_API_KEY="<your-api-key>" |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
AZURE_STORAGE_BLOB_ACCOUNT_NAME = "<account-name>" | ||
AZURE_STORAGE_BLOB_SAS_TOKEN = "<sas-token>" | ||
AZURE_STORAGE_BLOB_CONTAINER_NAME = "<blob-container-name>" |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from logging import getLogger | ||
|
||
from azure.ai.documentintelligence import DocumentIntelligenceClient | ||
from azure.ai.documentintelligence.models import AnalyzeDocumentRequest, AnalyzeResult, ContentFormat | ||
from azure.core.credentials import AzureKeyCredential | ||
|
||
from backend.settings.azure_ai_document_intelligence import Settings | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
class Client: | ||
def __init__(self, settings: Settings) -> None: | ||
self.settings = settings | ||
|
||
def get_document_intelligence_client(self) -> DocumentIntelligenceClient: | ||
return DocumentIntelligenceClient( | ||
endpoint=self.settings.azure_ai_document_intelligence_endpoint, | ||
credential=AzureKeyCredential(self.settings.azure_ai_document_intelligence_api_key), | ||
) | ||
|
||
def analyze_document( | ||
self, | ||
bytes_source: bytes, | ||
) -> AnalyzeResult: | ||
client = self.get_document_intelligence_client() | ||
poller = client.begin_analyze_document( | ||
model_id="prebuilt-read", | ||
analyze_request=AnalyzeDocumentRequest( | ||
bytes_source=bytes_source, | ||
), | ||
output_content_format=ContentFormat.MARKDOWN, | ||
) | ||
result = poller.result() | ||
logger.info(result) | ||
return result |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from logging import getLogger | ||
|
||
from fastapi import APIRouter, UploadFile | ||
|
||
from backend.internals.azure_ai_document_intelligence import Client | ||
from backend.schemas import azure_ai_document_intelligence as azure_ai_document_intelligence_schemas | ||
from backend.settings.azure_ai_document_intelligence import Settings | ||
|
||
logger = getLogger(__name__) | ||
|
||
client = Client( | ||
settings=Settings(), | ||
) | ||
|
||
router = APIRouter( | ||
prefix="/azure_ai_document_intelligence", | ||
tags=["azure_ai_document_intelligence"], | ||
responses={404: {"description": "Not found"}}, | ||
) | ||
|
||
|
||
@router.post( | ||
"/analyze_document/", | ||
response_model=azure_ai_document_intelligence_schemas.AnalyzeDocumentResponse, | ||
status_code=200, | ||
) | ||
async def analyze_document(file: UploadFile): | ||
try: | ||
content = await file.read() | ||
result = client.analyze_document( | ||
bytes_source=content, | ||
) | ||
except Exception as e: | ||
logger.error(f"Failed to read file: {e}") | ||
raise | ||
return azure_ai_document_intelligence_schemas.AnalyzeDocumentResponse( | ||
content=result.content, | ||
) |
This file contains 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
This file contains 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
Oops, something went wrong.