Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Azure/aihub
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendible committed Feb 28, 2024
2 parents 97caf81 + 80430c7 commit 9cc8c14
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 107 deletions.
12 changes: 6 additions & 6 deletions src/AIHub/Controllers/AudioTranscriptionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task<IActionResult> TranscribeAudio(string audio_url, IFormFile ima
request.Content = content;
var response = await httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
var responsejson = JsonConvert.DeserializeObject<dynamic>(await response.Content.ReadAsStringAsync())!;
var responsejson = JsonSerializer.Deserialize<dynamic>(await response.Content.ReadAsStringAsync())!;
Console.WriteLine(responsejson);
var output_result = responsejson.self.ToString();
Console.WriteLine("SELF: " + output_result);
Expand All @@ -56,13 +56,13 @@ public async Task<IActionResult> TranscribeAudio(string audio_url, IFormFile ima
var response2 = await httpClient.SendAsync(request2);
response2.EnsureSuccessStatusCode();
//Console.WriteLine(await response2.Content.ReadAsStringAsync());
var responsejson2 = JsonConvert.DeserializeObject<dynamic>(await response.Content.ReadAsStringAsync())!;
var responsejson2 = JsonSerializer.Deserialize<dynamic>(await response.Content.ReadAsStringAsync())!;
Console.WriteLine(responsejson2);
while (responsejson2.status != "Succeeded")
{
Thread.Sleep(10000);
response2 = await httpClient.GetAsync(output_result);
responsejson2 = JsonConvert.DeserializeObject<dynamic>(await response2.Content.ReadAsStringAsync())!;
responsejson2 = JsonSerializer.Deserialize<dynamic>(await response2.Content.ReadAsStringAsync())!;
Console.WriteLine(responsejson2.status);
}

Expand All @@ -74,7 +74,7 @@ public async Task<IActionResult> TranscribeAudio(string audio_url, IFormFile ima
request3.Content = content3;
var response3 = await httpClient.SendAsync(request3);
response3.EnsureSuccessStatusCode();
var responsejson3 = JsonConvert.DeserializeObject<dynamic>(await response3.Content.ReadAsStringAsync())!;
var responsejson3 = JsonSerializer.Deserialize<dynamic>(await response3.Content.ReadAsStringAsync())!;
Console.WriteLine(responsejson3);
// Extract contentUrl field
string output_result3 = (string)responsejson3["values"][0]["links"]["contentUrl"];
Expand All @@ -89,7 +89,7 @@ public async Task<IActionResult> TranscribeAudio(string audio_url, IFormFile ima
var response4 = await httpClient.SendAsync(request4);
response4.EnsureSuccessStatusCode();
Console.WriteLine(await response4.Content.ReadAsStringAsync());
var jsonObject4 = JsonConvert.DeserializeObject<JObject>(await response4.Content.ReadAsStringAsync())!;
var jsonObject4 = JsonSerializer.Deserialize<JsonObject>(await response4.Content.ReadAsStringAsync())!;
string output_result4 = (string)jsonObject4["combinedRecognizedPhrases"]![0]!["lexical"]!;
Console.WriteLine(output_result4);

Expand All @@ -103,7 +103,7 @@ public async Task<IActionResult> TranscribeAudio(string audio_url, IFormFile ima

public class SpeechToTextResponse
{
[JsonProperty("text")]
[JsonPropertyName("text")]
public string Text { get; set; } = string.Empty;
}

Expand Down
2 changes: 1 addition & 1 deletion src/AIHub/Controllers/BrandAnalyzerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task<IActionResult> AnalyzeCompany()
// Parse the response as JSON
try
{
var responsejson = JsonConvert.DeserializeObject<dynamic>(await response.Content.ReadAsStringAsync())!;
var responsejson = JsonSerializer.Deserialize<dynamic>(await response.Content.ReadAsStringAsync())!;

// Get the web pages from the response
var news = responsejson.webPages.value;
Expand Down
4 changes: 2 additions & 2 deletions src/AIHub/Controllers/DocumentComparisonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ public async Task<IActionResult> DocumentComparison(string[] document_urls, stri
HttpResponseMessage response2 = await httpClient.GetAsync(operation_location_url); // Blocking call! Program will wait here until a response is received or a timeout occurs.
Console.WriteLine(response2);
response2.EnsureSuccessStatusCode();
dynamic responsejson = JsonConvert.DeserializeObject<dynamic>(await response2.Content.ReadAsStringAsync())!;
dynamic responsejson = JsonSerializer.Deserialize<dynamic>(await response2.Content.ReadAsStringAsync())!;

while (responsejson.status != "succeeded")
{
if (response2 != null)
{
Thread.Sleep(10000);
response2 = await httpClient.GetAsync(operation_location_url);
responsejson = JsonConvert.DeserializeObject<dynamic>(await response2.Content.ReadAsStringAsync())!;
responsejson = JsonSerializer.Deserialize<dynamic>(await response2.Content.ReadAsStringAsync())!;
}
}
output_result[i] = responsejson.analyzeResult.content.ToString();
Expand Down
4 changes: 2 additions & 2 deletions src/AIHub/Controllers/FormAnalyzerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ public async Task<IActionResult> AnalyzeForm(string image_url, string prompt)
Console.WriteLine(response2);
response2.EnsureSuccessStatusCode();
var responseBody = await response2.Content.ReadAsStringAsync();
var responsejson = JsonConvert.DeserializeObject<dynamic>(await response2.Content.ReadAsStringAsync())!;
var responsejson = JsonSerializer.Deserialize<dynamic>(await response2.Content.ReadAsStringAsync())!;

//var analyzeresult = responseBody.analyzeResult;
while (responsejson.status != "succeeded")
{
Thread.Sleep(10000);
response2 = await httpClient.GetAsync(operation_location_url);
responsejson = JsonConvert.DeserializeObject<dynamic>(await response2.Content.ReadAsStringAsync())!;
responsejson = JsonSerializer.Deserialize<dynamic>(await response2.Content.ReadAsStringAsync())!;
}
output_result = responsejson.analyzeResult.content.ToString();

Expand Down
4 changes: 2 additions & 2 deletions src/AIHub/Controllers/ImageAnalyzerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async Task<IActionResult> DenseCaptionImage(string image_url)
// Parse the response as JSON
try
{
var responsejson = JsonConvert.DeserializeObject<dynamic>(await response.Content.ReadAsStringAsync())!;
var responsejson = JsonSerializer.Deserialize<dynamic>(await response.Content.ReadAsStringAsync())!;
// Get the web pages from the response
var dense_descriptions = responsejson.denseCaptionsResult.values;
// Iterate over the news items and print them
Expand Down Expand Up @@ -116,7 +116,7 @@ public async Task<IActionResult> DenseCaptionImage(string image_url)
// Parse the response as JSON
try
{
var responsejson2 = JsonConvert.DeserializeObject<dynamic>(await response2.Content.ReadAsStringAsync())!;
var responsejson2 = JsonSerializer.Deserialize<dynamic>(await response2.Content.ReadAsStringAsync())!;
Console.WriteLine(responsejson2.ToString());
// Get the web pages from the response
var ocr = responsejson2.readResult.content;
Expand Down
3 changes: 1 addition & 2 deletions src/AIHub/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
global using Azure.Storage.Blobs.Models;
global using Azure.AI.OpenAI;
global using System.Net.Http.Headers;
global using Newtonsoft.Json;
global using Newtonsoft.Json.Linq;
global using System.Text;
global using System.Text.Json;
global using System.Text.Json.Nodes;
global using System.Text.Json.Serialization;
Loading

0 comments on commit 9cc8c14

Please sign in to comment.