Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Oct 9, 2024
2 parents 1c449f1 + 3f0a1c5 commit b29bf9c
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 86 deletions.
13 changes: 13 additions & 0 deletions AiServer.ServiceInterface/Generation/ComfyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ private ComfyClient GetClient(MediaProvider provider)
// Last check for null seed
request.Seed ??= Random.Shared.Next();
var comfyWorkflowReq = request.ConvertTo<ComfyWorkflowRequest>();
// Ensure task type is set
comfyWorkflowReq.TaskType = request.TaskType switch
{
AiTaskType.TextToImage => ComfyTaskType.TextToImage,
AiTaskType.ImageToImage => ComfyTaskType.ImageToImage,
AiTaskType.ImageUpscale => ComfyTaskType.ImageUpscale,
AiTaskType.ImageWithMask => ComfyTaskType.ImageWithMask,
AiTaskType.ImageToText => ComfyTaskType.ImageToText,
AiTaskType.TextToAudio => ComfyTaskType.TextToAudio,
AiTaskType.TextToSpeech => ComfyTaskType.TextToSpeech,
AiTaskType.SpeechToText => ComfyTaskType.SpeechToText,
_ => throw new ArgumentOutOfRangeException()
};
comfyWorkflowReq =
comfyWorkflowReq.ApplyModelDefaults(AppConfig.Instance, modelSettings.ConvertTo<ComfyApiModelSettings>());
var response = await comfyClient.PromptGenerationAsync(comfyWorkflowReq, token, waitResult: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,10 @@ async Task DownloadOutputAsync(IMediaTransformProvider aiProvider,
"video/mp4" => "mp4",
"video/webm" => "webm",
"video/ogg" => "ogg",
_ => "webm"
"video/mov" => "mov",
"video/avi" => "avi",
"video/mkv" => "mkv",
_ => "mp4"
};

var imageBytes = await response.Content.ReadAsByteArrayAsync();
Expand Down
6 changes: 3 additions & 3 deletions AiServer.ServiceInterface/VideoServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ public async Task<object> Any(TrimVideo request)

private void ValidateTimeFormat(string time, string fieldName)
{
if (!Regex.IsMatch(time, @"^\d{2}:\d{2}$"))
if (!Regex.IsMatch(time, @"^(\d{1,3}):([0-5]\d)$"))
{
throw new ArgumentException($"Invalid {fieldName} format. Expected format: mm:ss");
throw new ArgumentException($"Invalid {fieldName} format. Expected format: m:ss, mm:ss, or mmm:ss");
}
}

Expand Down Expand Up @@ -198,8 +198,8 @@ private bool IsVideoFormat(MediaOutputFormat outputFormat)
case MediaOutputFormat.MKV:
case MediaOutputFormat.MOV:
case MediaOutputFormat.WebM:
return true;
case MediaOutputFormat.GIF:
return true;
case MediaOutputFormat.MP3:
case MediaOutputFormat.WAV:
case MediaOutputFormat.FLAC:
Expand Down
2 changes: 1 addition & 1 deletion AiServer.ServiceModel/GenerationAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class CreateMediaProvider : ICreateDb<MediaProvider>, IReturn<IdResponse>
public List<string>? Models { get; set; }

[Input(Type = "hidden")]
public int? MediaTypeId { get; set; }
public string MediaTypeId { get; set; }
}

[Tag(Tag.Info)]
Expand Down
8 changes: 4 additions & 4 deletions AiServer.ServiceModel/MediaTransforms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,13 @@ public class CropVideo : IMediaTransform, IReturn<MediaTransformResponse>
[ValidateApiKey]
public class TrimVideo : IMediaTransform, IReturn<MediaTransformResponse>
{
[ApiMember(Description = "The start time of the trimmed video (format: HH:MM:SS)")]
[Description("The start time of the trimmed video (format: HH:MM:SS)")]
[ApiMember(Description = "The start time of the trimmed video (format: MM:SS)")]
[Description("The start time of the trimmed video (format: MM:SS)")]
[Required]
public string StartTime { get; set; }

[ApiMember(Description = "The end time of the trimmed video (format: HH:MM:SS)")]
[Description("The end time of the trimmed video (format: HH:MM:SS)")]
[ApiMember(Description = "The end time of the trimmed video (format: MM:SS)")]
[Description("The end time of the trimmed video (format: MM:SS)")]
public string? EndTime { get; set; }

[Required]
Expand Down
22 changes: 14 additions & 8 deletions AiServer.ServiceModel/QueueMediaTransforms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public class QueueWatermarkImage : IQueueMediaTransform, IPost, IReturn<QueueMed
[Description("Scale an image to a specified size")]
[Tag("Media")]
[ValidateApiKey]
public class QueueScaleImage : IPost, IReturn<MediaTransformResponse>
public class QueueScaleImage : IQueueMediaTransform,IPost, IReturn<MediaTransformResponse>
{
[ApiMember(Description = "The image file to be scaled")]
[Description("The image file to be scaled")]
Expand All @@ -235,6 +235,18 @@ public class QueueScaleImage : IPost, IReturn<MediaTransformResponse>
[ApiMember(Description = "Desired height of the scaled image")]
[Description("Desired height of the scaled image")]
public int? Height { get; set; }

[ApiMember(Description = "Optional client-provided identifier for the request")]
[Description("Optional client-provided identifier for the request")]
public string? RefId { get; set; }

[ApiMember(Description = "Optional queue or topic to reply to")]
[Description("Optional queue or topic to reply to")]
public string? ReplyTo { get; set; }

[ApiMember(Description = "Tag to identify the request")]
[Description("Tag to identify the request")]
public string? Tag { get; set; }
}

[Description("Convert a video to a different format")]
Expand Down Expand Up @@ -375,14 +387,8 @@ public enum ConvertVideoOutputFormat
MP4,
[EnumMember(Value = "avi")]
AVI,
[EnumMember(Value = "mkv")]
MKV,
[EnumMember(Value = "mov")]
MOV,
[EnumMember(Value = "webm")]
WebM,
[EnumMember(Value = "gif")]
GIF
MOV
}

[DataContract]
Expand Down
68 changes: 2 additions & 66 deletions AiServer.Tests/ComfyAdminTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,70 +12,6 @@ public class ComfyAdminTasks
{
private static bool useLocal = true;
private ConfigureSecrets ConfigureSecrets = new();

public static Dictionary<string, ComfyApiModelSettings> ImportCivitAiModelSettings = new()
{
{
"https://civitai.com/models/194768/jib-mix-realistic-xl?modelVersionId=610292",
new ComfyApiModelSettings
{
Height = 1024,
Width = 1024,
Sampler = ComfySampler.euler_ancestral,
Scheduler = "karras",
CfgScale = 6.0,
Steps = 18
}
},
{
"https://civitai.com/models/553410/crazycaricaturesxl?modelVersionId=615871",
new ComfyApiModelSettings
{
Height = 1024,
Width = 1024,
Sampler = ComfySampler.euler_ancestral,
Scheduler = "normal",
CfgScale = 8.0,
Steps = 18
}
},
{
"https://civitai.com/models/129403?modelVersionId=259194",
new ComfyApiModelSettings
{
Height = 1024,
Width = 1024,
Sampler = ComfySampler.euler_ancestral,
Scheduler = "normal",
CfgScale = 3.0,
Steps = 12
}
},
{
"https://civitai.com/models/157665/lah-hongchen-or-sdxl-and-sd15",
new ComfyApiModelSettings
{
Height = 1024,
Width = 1024,
Sampler = ComfySampler.euler,
Scheduler = "normal",
CfgScale = 1.0,
Steps = 8
}
},
{
"https://civitai.com/models/350352?modelVersionId=391971",
new ComfyApiModelSettings
{
Height = 1024,
Width = 1024,
Sampler = ComfySampler.euler,
Scheduler = "normal",
CfgScale = 1.0,
Steps = 8
}
}
};

private static List<CreateMediaProvider> MediaProviders = new List<CreateMediaProvider>
{
Expand All @@ -88,7 +24,7 @@ public class ComfyAdminTasks
HeartbeatUrl = "https://api.replicate.com/",
ApiBaseUrl = "https://api.replicate.com/",
Models = new List<string> { "flux1-dev","flux1-schnell" },
MediaTypeId = 1
MediaTypeId = "ConfyUI"
},
new()
{
Expand All @@ -105,7 +41,7 @@ public class ComfyAdminTasks
"animexlXuebimix_v60LCM.safetensors",
"LahHongchenSDXLSD15_xlLightning.safetensors"
},
MediaTypeId = 2
MediaTypeId = "ComfyUI"
}
};

Expand Down
9 changes: 6 additions & 3 deletions AiServer/wwwroot/mjs/components/MediaProviders.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ const SelectModels = {
}
return;
} else {
supportedModels.value = Object.keys(props.providerType?.apiModels, [])
qualifiedModelMappings.value = props.providerType?.apiModels
if (props.providerType?.apiModels) {
console.log(props.providerType?.apiModels)
supportedModels.value = Object.keys(props.providerType?.apiModels, [])
qualifiedModelMappings.value = props.providerType?.apiModels
}
}
comfyModels.value = []
isConnectionTested.value = false
Expand Down Expand Up @@ -212,7 +215,7 @@ export default {
<span class="flex flex-1">
<Icon :src="type.icon" class="w-5 h-5 mr-2" />
<span class="flex flex-col">
<span class="block text-sm font-medium text-gray-900">{{type.name}}</span>
<span class="block text-sm font-medium text-gray-900">{{type.id}}</span>
</span>
</span>
<svg v-if="providerType == type.id" class="h-5 w-5 text-indigo-600" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
Expand Down

0 comments on commit b29bf9c

Please sign in to comment.