Azure AI services - Extract form data in Document Intelligence Studio:
using Azure;
using Azure.AI.DocumentIntelligence;
public class Program
{
public static async Task Main(string[] args)
{
string endpoint = "https://dir1.cognitiveservices.azure.com/"; // "YOUR_FORM_RECOGNIZER_ENDPOINT";
string apiKey = "60c7be9d64fa32764c98b6xbx8x9xd6"; //"YOUR_FORM_RECOGNIZER_KEY";
AzureKeyCredential credential = new AzureKeyCredential(apiKey);
DocumentIntelligenceClient client = new DocumentIntelligenceClient(new Uri(endpoint),
credential);
Uri
receiptUri = new Uri("https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/formrecognizer/azure-ai-formrecognizer/tests/sample_forms/receipt/contoso-receipt.png");
Operation<AnalyzeResult> operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-receipt", receiptUri);
AnalyzeResult receipts = operation.Value;
foreach (AnalyzedDocument receipt in receipts.Documents)
{
if (receipt.Fields.TryGetValue("MerchantName", out DocumentField merchantNameField))
{
if (merchantNameField.FieldType == DocumentFieldType.String)
{
string merchantName = merchantNameField.ValueString;
Console.WriteLine($"Merchant Name: '{merchantName}',
with confidence {merchantNameField.Confidence}");
}
}
if (receipt.Fields.TryGetValue("TransactionDate", out DocumentField transactionDateField))
{
if (transactionDateField.FieldType == DocumentFieldType.Date)
{
DateTimeOffset? transactionDate = transactionDateField.ValueDate;
Console.WriteLine($"Transaction Date: '{transactionDate}',
with confidence {transactionDateField.Confidence}");
}
}
if (receipt.Fields.TryGetValue("Items", out DocumentField itemsField))
{
if (itemsField.FieldType == DocumentFieldType.List)
{
foreach (DocumentField itemField in itemsField.ValueList)
{
Console.WriteLine("Item:");
if (itemField.FieldType == DocumentFieldType.Dictionary)
{
IReadOnlyDictionary<string, DocumentField> itemFields = itemField.ValueDictionary;
if (itemFields.TryGetValue("Description", out DocumentField itemDescriptionField))
{
if (itemDescriptionField.FieldType == DocumentFieldType.String)
{
string itemDescription = itemDescriptionField.ValueString;
Console.WriteLine($"
Description: '{itemDescription}', with confidence {itemDescriptionField.Confidence}");
}
}
if (itemFields.TryGetValue("TotalPrice", out DocumentField itemTotalPriceField))
{
if (itemTotalPriceField.FieldType == DocumentFieldType.Currency)
{
double? itemTotalPrice = itemTotalPriceField.ValueCurrency.Amount;
Console.WriteLine($"
Total Price: '{itemTotalPrice}', with confidence {itemTotalPriceField.Confidence}");
}
}
}
}
}
}
if (receipt.Fields.TryGetValue("Total", out DocumentField totalField))
{
if (totalField.FieldType == DocumentFieldType.Currency)
{
double total = totalField.ValueCurrency.Amount;
Console.WriteLine($"Total: '{total}', with confidence '{totalField.Confidence}'");
}
}
}
Console.ReadKey();
}
}
C# Code:
using Azure;
{
public static async Task Main(string[] args)
{
string endpoint = "https://dir1.cognitiveservices.azure.com/"; // "YOUR_FORM_RECOGNIZER_ENDPOINT";
string apiKey = "60c7be9d64fa32764c98b6xbx8x9xd6"; //"YOUR_FORM_RECOGNIZER_KEY";
AzureKeyCredential credential = new AzureKeyCredential(apiKey);
{
if (receipt.Fields.TryGetValue("MerchantName", out DocumentField merchantNameField))
{
if (merchantNameField.FieldType == DocumentFieldType.String)
{
string merchantName = merchantNameField.ValueString;
}
if (receipt.Fields.TryGetValue("TransactionDate", out DocumentField transactionDateField))
{
if (transactionDateField.FieldType == DocumentFieldType.Date)
{
DateTimeOffset? transactionDate = transactionDateField.ValueDate;
}
if (receipt.Fields.TryGetValue("Items", out DocumentField itemsField))
{
if (itemsField.FieldType == DocumentFieldType.List)
{
foreach (DocumentField itemField in itemsField.ValueList)
{
Console.WriteLine("Item:");
{
IReadOnlyDictionary<string, DocumentField> itemFields = itemField.ValueDictionary;
{
if (itemDescriptionField.FieldType == DocumentFieldType.String)
{
string itemDescription = itemDescriptionField.ValueString;
}
if (itemFields.TryGetValue("TotalPrice", out DocumentField itemTotalPriceField))
{
if (itemTotalPriceField.FieldType == DocumentFieldType.Currency)
{
double? itemTotalPrice = itemTotalPriceField.ValueCurrency.Amount;
}
}
}
}
}
if (receipt.Fields.TryGetValue("Total", out DocumentField totalField))
{
if (totalField.FieldType == DocumentFieldType.Currency)
{
double total = totalField.ValueCurrency.Amount;
}
}
Console.ReadKey();
}
Output:
Python Code:
# pip install azure-ai-documentintelligence==1.0.0b4
key = "8ajYtpyzoJtV0bddxOpfZkmooJJQQJ99BAACYeBjFXJ3w3AAALACOGwbWr"
endpoint = endpoint, credential = AzureKeyCredential(key)
)
"prebuilt-receipt", AnalyzeDocumentRequest(url_source = url)
receipts = poller.result()
if receipt_type:
"Receipt Type: {}".format(receipt_type)
merchant_name = receipt.fields.get("MerchantName")
"Merchant Name: {} has confidence: {}".format(
)
)
transaction_date = receipt.fields.get("TransactionDate")
"Transaction Date: {} has confidence: {}".format(
transaction_date.value_date, transaction_date.confidence
)
)
if receipt.fields.get("Items"):
for idx, item in enumerate(receipt.fields.get("Items").value_array):
item_description = item.value_object.get("Description")
if item_description:
"......Item Description: {} has confidence: {}".format(
item_description.value_string, item_description.confidence
)
)
item_quantity = item.value_object.get("Quantity")
if item_quantity:
"......Item Quantity: {} has confidence: {}".format(
item_quantity.value_number, item_quantity.confidence
)
)
item_price = item.value_object.get("Price")
if item_price:
"......Individual Item Price: {} has confidence: {}".format(
item_price.value_currency.amount, item_price.confidence
)
)
item_total_price = item.value_object.get("TotalPrice")
if item_total_price:
"......Total Item Price: {} has confidence: {}".format(
item_total_price.value_currency.amount, item_total_price.confidence
)
)
subtotal = receipt.fields.get("Subtotal")
if subtotal:
"Subtotal: {} has confidence: {}".format(
subtotal.value_currency.amount, subtotal.confidence
)
)
tax = receipt.fields.get("TotalTax")
if tax:
tip = receipt.fields.get("Tip")
if tip:
total = receipt.fields.get("Total")
if total:
print("--------------------------------------")
OutPut:
43C1F1FD05
ReplyDeleteCam Åžov
Canlı Cam Show
Görüntülü Sex Sohbet
Azure AI Document Intelligence can extract structured information from documents such as receipts by using prebuilt AI models. The C# example demonstrates how an application can authenticate with Azure, analyze a receipt, and retrieve fields such as merchant name, transaction date, individual items, prices, and the total amount along with confidence scores.
DeleteThis type of intelligent document processing can also be connected with modern AI applications for automated information extraction, summarization, and workflow automation. Developers interested in building applications around AI-powered document analysis can explore ChatGPT Developer Training to understand how AI capabilities can be integrated into practical software solutions.
Document Intelligence and automated extraction also provide useful directions for academic and final-year projects involving AI-based document processing. Students can explore Generative AI Projects for Final Year for project ideas involving intelligent content processing, AI-assisted applications, and emerging generative AI technologies.
DeleteThis type of AI-powered document processing also highlights the importance of understanding how people interact with AI tools and how AI can support practical development workflows. Developers exploring this area can refer to Are You Thinking With AI Or Just Thinking At It for a related perspective on using AI thoughtfully in technology projects.
DeleteA859C6C9A883
ReplyDeleteSosyal medya hesaplarınızın görünürlüğünü artırmak ve takipçi sayınızı hızlıca yükseltmek istiyorsanız çeşitli hizmetler sunan platformları araştırmanız faydalı olacaktır. Bu noktada güvenilir smm panel seçeneklerini değerlendirmek hem kaliteli hizmet almanızı sağlar hem de uzun vadeli başarı elde etmenize yardımcı olur. Güvenilir ve etkili sonuçlar için bu tür panellerin kullanıcı yorumlarını incelemeniz önemlidir. Doğru tercihleri yaparak sosyal medyada fark yaratabilirsiniz.
AI house designs continue to impress. interior ai
ReplyDeleteDiscovery I recently visited this impressive website deskpins and appreciated its clean structure, accessible features, and reliable performance. The platform creates a positive experience by making navigation simple and providing practical value for users across different needs.
ReplyDeleteNova I recently explored the online platform mousecape and appreciated its user friendly design, practical features, and clear organization. The website helps visitors access information efficiently while providing a dependable environment that encourages continued engagement and satisfaction over time.
ReplyDelete