Skip to content

Commit 2118b57

Browse files
committed
Update AI Server examples
1 parent e3c04c2 commit 2118b57

26 files changed

+85
-42
lines changed

MyApp/_includes/ai-server/cs/convert-image-1.cs.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ var response = client.PostFileWithRequest(new ConvertImage {
55
},
66
new UploadFile("test_image.jpg", fsImage, "image"));
77

8-
var videoUrl = response.Results[0].Url;
9-
videoUrl.DownloadFileTo(outputFileName);
8+
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
109
```

MyApp/_includes/ai-server/cs/convert-video-1.cs.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ var response = client.PostFileWithRequest(new ConvertVideo {
55
},
66
new UploadFile("test_video.webm", fsVideo, "video"));
77

8-
var videoUrl = response.Results[0].Url;
9-
videoUrl.DownloadFileTo(outputFileName);
8+
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
109
```

MyApp/_includes/ai-server/cs/crop-image-1.cs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ var response = client.PostFileWithRequest(new CropImage {
99
new UploadFile("test_image.jpg", fsImage, "image"));
1010

1111
var videoUrl = response.Results[0].Url;
12-
videoUrl.DownloadFileTo(outputFileName);
12+
videoUrl.DownloadFileTo(saveToPath);
1313
```

MyApp/_includes/ai-server/cs/crop-video-1.cs.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ var response = client.PostFileWithRequest(new CropVideo {
88
},
99
new UploadFile("test_video.mp4", fsVideo, "video"));
1010

11-
var videoUrl = response.Results[0].Url;
12-
videoUrl.DownloadFileTo(outputFileName);
11+
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
1312
```

MyApp/_includes/ai-server/cs/image-upscale-1.cs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ using var fsImage = File.OpenRead("files/test_image.jpg");
33
var response = client.PostFileWithRequest(new ImageUpscale(),
44
new UploadFile("image", fsImage, "image"));
55

6-
response.Results[0].Url.DownloadFileTo(outputFileName);
6+
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
77
```

MyApp/_includes/ai-server/cs/image-with-mask-1.cs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ var response = client.PostFilesWithRequest(new ImageWithMask {
99
new UploadFile("mask", fsMask, "mask")
1010
]);
1111

12-
response.Results[0].Url.DownloadFileTo(outputFileName);
12+
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
1313
```

MyApp/_includes/ai-server/cs/queue-convert-image-1.cs.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queue
1212
await Task.Delay(1000);
1313
}
1414

15-
// Download the converted video
16-
var videoUrl = status.Results[0].Url;
17-
videoUrl.DownloadFileTo(outputFileName);
15+
// Download the converted image
16+
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
1817
```

MyApp/_includes/ai-server/cs/queue-crop-image-1.cs.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queue
1515
await Task.Delay(1000);
1616
}
1717

18-
// Download the cropped video
19-
var videoUrl = status.Results[0].Url;
20-
videoUrl.DownloadFileTo($"cropped-image-{status.RefId}.jpg");
18+
// Download the cropped image
19+
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
2120
```

MyApp/_includes/ai-server/cs/queue-crop-video-1.cs.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queue
1717
}
1818

1919
// Download the cropped video
20-
var videoUrl = status.Results[0].Url;
21-
videoUrl.DownloadFileTo($"cropped-video-{status.RefId}.mp4");
20+
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
2221
```

MyApp/_includes/ai-server/cs/queue-image-to-image-1.cs.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,16 @@ var response = client.PostFileWithRequest(new QueueImageToImage {
55
NegativePrompt = "A pixelated, low-quality image"
66
},
77
new UploadFile("image", fsImage, "image"));
8+
9+
// Poll for Job Completion Status
10+
GetArtifactGenerationStatusResponse status = new();
11+
while (status.JobState is BackgroundJobState.Queued or BackgroundJobState.Started)
12+
{
13+
status = client.Get(new GetArtifactGenerationStatus { JobId = response.JobId });
14+
Thread.Sleep(1000);
15+
}
16+
if (status.Results?.Count > 0)
17+
{
18+
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
19+
}
820
```

0 commit comments

Comments
 (0)