Skip to content

Commit f8984b6

Browse files
committed
Enabled faster hat training and reset of the AI iteration
1 parent e4ae39c commit f8984b6

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

Fritz.Chatbot/Commands/PredictHatCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class PredictHatCommand : IBasicCommand
2424
private string _TwitchChannel = "";
2525
private Guid _AzureProjectId;
2626

27-
private static string _IterationName = "";
27+
internal static string IterationName = "";
2828
private ScreenshotTrainingService _TrainHat;
2929

3030
public PredictHatCommand(IConfiguration configuration, ScreenshotTrainingService service)
@@ -42,7 +42,7 @@ public PredictHatCommand(IConfiguration configuration, ScreenshotTrainingService
4242
public async Task Execute(IChatService chatService, string userName, ReadOnlyMemory<char> rhs)
4343
{
4444

45-
if (string.IsNullOrEmpty(_IterationName)) {
45+
if (string.IsNullOrEmpty(IterationName)) {
4646
await IdentifyIterationName();
4747
}
4848

@@ -59,7 +59,7 @@ public async Task Execute(IChatService chatService, string userName, ReadOnlyMem
5959
ImagePrediction result;
6060
try
6161
{
62-
result = await client.DetectImageWithNoStoreAsync(_AzureProjectId, _IterationName, obsImage);
62+
result = await client.DetectImageWithNoStoreAsync(_AzureProjectId, IterationName, obsImage);
6363
} catch (CustomVisionErrorException ex) {
6464

6565

@@ -94,7 +94,7 @@ private async Task IdentifyIterationName()
9494
};
9595

9696
var iterations = await client.GetIterationsAsync(_AzureProjectId);
97-
_IterationName = iterations
97+
IterationName = iterations
9898
.Where(i => !string.IsNullOrEmpty(i.PublishName) && i.Status == "Completed")
9999
.OrderByDescending(i => i.LastModified).First().PublishName;
100100

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Fritz.StreamLib.Core;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Fritz.Chatbot.Commands
8+
{
9+
public class ResetHatAiCommand : IBasicCommand2
10+
{
11+
12+
public string Trigger => "resethatai";
13+
public string Description => "Reset the Hat detection AI after adding new hats";
14+
public TimeSpan? Cooldown { get; } = TimeSpan.FromSeconds(30);
15+
16+
public async Task Execute(IChatService chatService, string userName, bool isModerator, bool isVip, bool isBroadcaster, ReadOnlyMemory<char> rhs)
17+
{
18+
19+
if (!(isModerator || isBroadcaster)) return;
20+
21+
PredictHatCommand.IterationName = string.Empty;
22+
await chatService.SendMessageAsync("Reset the AI iteration and will detect the latest for Hat identification next time !hat is called");
23+
24+
}
25+
26+
public Task Execute(IChatService chatService, string userName, ReadOnlyMemory<char> rhs)
27+
{
28+
return Task.CompletedTask;
29+
}
30+
}
31+
}

Fritz.Chatbot/Commands/TrainHatCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public async Task Execute(IChatService chatService, string userName, bool isMode
2626
if (!(isModerator || isBroadcaster)) return;
2727

2828
_TrainHat.StartTraining();
29-
await chatService.SendMessageAsync("Started taking screenshots, 1 per minute for the next 15 minutes");
29+
await chatService.SendMessageAsync("Started taking screenshots, 1 every ten seconds for the next 150 seconds");
3030

3131
}
3232

Fritz.Chatbot/ScreenshotTrainingService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private async Task Train(CancellationToken token)
7979
{
8080

8181
await AddScreenshot(true);
82-
await Task.Delay(TimeSpan.FromMinutes(1));
82+
await Task.Delay(TimeSpan.FromSeconds(10));
8383

8484
}
8585
else

0 commit comments

Comments
 (0)