Skip to content

Commit

Permalink
Update AI Server examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Nov 25, 2024
1 parent e3c04c2 commit 2118b57
Show file tree
Hide file tree
Showing 26 changed files with 85 additions and 42 deletions.
3 changes: 1 addition & 2 deletions MyApp/_includes/ai-server/cs/convert-image-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ var response = client.PostFileWithRequest(new ConvertImage {
},
new UploadFile("test_image.jpg", fsImage, "image"));

var videoUrl = response.Results[0].Url;
videoUrl.DownloadFileTo(outputFileName);
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
```
3 changes: 1 addition & 2 deletions MyApp/_includes/ai-server/cs/convert-video-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ var response = client.PostFileWithRequest(new ConvertVideo {
},
new UploadFile("test_video.webm", fsVideo, "video"));

var videoUrl = response.Results[0].Url;
videoUrl.DownloadFileTo(outputFileName);
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
```
2 changes: 1 addition & 1 deletion MyApp/_includes/ai-server/cs/crop-image-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ var response = client.PostFileWithRequest(new CropImage {
new UploadFile("test_image.jpg", fsImage, "image"));

var videoUrl = response.Results[0].Url;
videoUrl.DownloadFileTo(outputFileName);
videoUrl.DownloadFileTo(saveToPath);
```
3 changes: 1 addition & 2 deletions MyApp/_includes/ai-server/cs/crop-video-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ var response = client.PostFileWithRequest(new CropVideo {
},
new UploadFile("test_video.mp4", fsVideo, "video"));

var videoUrl = response.Results[0].Url;
videoUrl.DownloadFileTo(outputFileName);
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
```
2 changes: 1 addition & 1 deletion MyApp/_includes/ai-server/cs/image-upscale-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ using var fsImage = File.OpenRead("files/test_image.jpg");
var response = client.PostFileWithRequest(new ImageUpscale(),
new UploadFile("image", fsImage, "image"));

response.Results[0].Url.DownloadFileTo(outputFileName);
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
```
2 changes: 1 addition & 1 deletion MyApp/_includes/ai-server/cs/image-with-mask-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ var response = client.PostFilesWithRequest(new ImageWithMask {
new UploadFile("mask", fsMask, "mask")
]);

response.Results[0].Url.DownloadFileTo(outputFileName);
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
```
5 changes: 2 additions & 3 deletions MyApp/_includes/ai-server/cs/queue-convert-image-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queue
await Task.Delay(1000);
}

// Download the converted video
var videoUrl = status.Results[0].Url;
videoUrl.DownloadFileTo(outputFileName);
// Download the converted image
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
```
5 changes: 2 additions & 3 deletions MyApp/_includes/ai-server/cs/queue-crop-image-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queue
await Task.Delay(1000);
}

// Download the cropped video
var videoUrl = status.Results[0].Url;
videoUrl.DownloadFileTo($"cropped-image-{status.RefId}.jpg");
// Download the cropped image
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
```
3 changes: 1 addition & 2 deletions MyApp/_includes/ai-server/cs/queue-crop-video-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queue
}

// Download the cropped video
var videoUrl = status.Results[0].Url;
videoUrl.DownloadFileTo($"cropped-video-{status.RefId}.mp4");
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
```
12 changes: 12 additions & 0 deletions MyApp/_includes/ai-server/cs/queue-image-to-image-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@ var response = client.PostFileWithRequest(new QueueImageToImage {
NegativePrompt = "A pixelated, low-quality image"
},
new UploadFile("image", fsImage, "image"));

// Poll for Job Completion Status
GetArtifactGenerationStatusResponse status = new();
while (status.JobState is BackgroundJobState.Queued or BackgroundJobState.Started)
{
status = client.Get(new GetArtifactGenerationStatus { JobId = response.JobId });
Thread.Sleep(1000);
}
if (status.Results?.Count > 0)
{
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
}
```
12 changes: 12 additions & 0 deletions MyApp/_includes/ai-server/cs/queue-image-to-text-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@
using var fsImage = File.OpenRead("files/test_image.jpg");
var response = client.PostFileWithRequest(new QueueImageToText(),
new UploadFile("image", fsImage, "image"));

// Poll for Job Completion Status
GetTextGenerationStatusResponse status = new();
while (status.JobState is BackgroundJobState.Queued or BackgroundJobState.Started)
{
status = client.Get(new GetTextGenerationStatus { JobId = response.JobId });
Thread.Sleep(1000);
}
if (status.Results?.Count > 0)
{
var answer = status.Results[0].Text;
}
```
12 changes: 12 additions & 0 deletions MyApp/_includes/ai-server/cs/queue-image-upscale-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@
using var fsImage = File.OpenRead("files/test_image.jpg");
var response = client.PostFileWithRequest(new QueueImageUpscale(),
new UploadFile("image", fsImage, "image"));

// Poll for Job Completion Status
GetArtifactGenerationStatusResponse status = new();
while (status.JobState is BackgroundJobState.Queued or BackgroundJobState.Started)
{
status = client.Get(new GetArtifactGenerationStatus { JobId = response.JobId });
Thread.Sleep(1000);
}
if (status.Results?.Count > 0)
{
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
}
```
12 changes: 12 additions & 0 deletions MyApp/_includes/ai-server/cs/queue-image-with-mask-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,16 @@ var response = client.PostFilesWithRequest(new QueueImageWithMask {
new UploadFile("image", fsImage, "image"),
new UploadFile("mask", fsMask, "mask")
]);

// Poll for Job Completion Status
GetArtifactGenerationStatusResponse status = new();
while (status.JobState is BackgroundJobState.Queued or BackgroundJobState.Started)
{
status = client.Get(new GetArtifactGenerationStatus { JobId = response.JobId });
Thread.Sleep(1000);
}
if (status.Results?.Count > 0)
{
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
}
```
5 changes: 2 additions & 3 deletions MyApp/_includes/ai-server/cs/queue-scale-image-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queue
await Task.Delay(1000);
}

// Download the scaled video
var videoUrl = status.Results[0].Url;
videoUrl.DownloadFileTo($"scaled-image-{status.RefId}.jpg");
// Download the scaled image
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
```
3 changes: 1 addition & 2 deletions MyApp/_includes/ai-server/cs/queue-scale-video-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queue
}

// Download the scaled video
var videoUrl = status.Results[0].Url;
videoUrl.DownloadFileTo($"scaled-video-{status.RefId}.mp4");
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
```
12 changes: 12 additions & 0 deletions MyApp/_includes/ai-server/cs/queue-text-to-image-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,16 @@ var response = client.Post(new QueueTextToImage
PositivePrompt = "A happy llama",
NegativePrompt = "bad quality, blurry image"
});

// Poll for Job Completion Status
GetArtifactGenerationStatusResponse status = new();
while (status.JobState is BackgroundJobState.Queued or BackgroundJobState.Started)
{
status = client.Get(new GetArtifactGenerationStatus { JobId = response.JobId });
Thread.Sleep(1000);
}
if (status.Results?.Count > 0)
{
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
}
```
3 changes: 1 addition & 2 deletions MyApp/_includes/ai-server/cs/queue-trim-video-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queue
}

// Download the trimmed video
var videoUrl = status.Results[0].Url;
videoUrl.DownloadFileTo($"trimmed-video-{status.RefId}.mp4");
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
```
3 changes: 1 addition & 2 deletions MyApp/_includes/ai-server/cs/queue-video-convert-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queue
}

// Download the converted video
var videoUrl = status.Results[0].Url;
videoUrl.DownloadFileTo(outputFileName);
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
```
5 changes: 2 additions & 3 deletions MyApp/_includes/ai-server/cs/queue-watermark-image-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queue
await Task.Delay(1000);
}

// Download the watermarked video
var videoUrl = status.Results[0].Url;
videoUrl.DownloadFileTo($"watermarked-image-{status.RefId}.jpg");
// Download the watermarked image
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
```
3 changes: 1 addition & 2 deletions MyApp/_includes/ai-server/cs/queue-watermark-video-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ while (status.JobState is BackgroundJobState.Started or BackgroundJobState.Queue
}

// Download the watermarked video
var videoUrl = status.Results[0].Url;
videoUrl.DownloadFileTo($"watermarked-video-{status.RefId}.mp4");
File.WriteAllBytes(saveToPath, status.Results[0].Url.GetBytesFromUrl());
```
3 changes: 1 addition & 2 deletions MyApp/_includes/ai-server/cs/scale-image-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ var response = client.PostFileWithRequest(new ScaleImage {
},
new UploadFile("test_image.jpg", fsImage, "image"));

var videoUrl = response.Results[0].Url;
videoUrl.DownloadFileTo(outputFileName);
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
```
3 changes: 1 addition & 2 deletions MyApp/_includes/ai-server/cs/scale-video-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ var response = client.PostFileWithRequest(new ScaleVideo {
},
new UploadFile("test_video.mp4", fsVideo, "video"));

var videoUrl = response.Results[0].Url;
videoUrl.DownloadFileTo(outputFileName);
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
```
2 changes: 1 addition & 1 deletion MyApp/_includes/ai-server/cs/text-to-image-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ var response = client.Post(new TextToImage
PositivePrompt = "A happy llama",
NegativePrompt = "bad quality, blurry image"
});
response.Results[0].Url.DownloadFileTo(outputFileName);
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
```
3 changes: 1 addition & 2 deletions MyApp/_includes/ai-server/cs/trim-video-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ var response = client.PostFileWithRequest(new TrimVideo {
},
new UploadFile("test_video.mp4", fsVideo, "video"));

var videoUrl = response.Results[0].Url;
videoUrl.DownloadFileTo(outputFileName);
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
```
3 changes: 1 addition & 2 deletions MyApp/_includes/ai-server/cs/watermark-image-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ var response = client.PostFilesWithRequest(new WatermarkImage {
new UploadFile("watermark_image.png", fsWatermark, "watermark")
]);

var videoUrl = response.Results[0].Url;
videoUrl.DownloadFileTo(outputFileName);
File.WriteAllBytes(saveToPath, response.Results[0].Url.GetBytesFromUrl());
```
3 changes: 1 addition & 2 deletions MyApp/_includes/ai-server/cs/watermark-video-1.cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ var response = client.PostFilesWithRequest(new WatermarkVideo {
new UploadFile("watermark_image.png", fsWatermark, "watermark")
]);

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

0 comments on commit 2118b57

Please sign in to comment.