Пример #1
0
        private void UpdateCodeWindows(int newStart)
        {
            var cursorPos = GetCursorPos(this.codeDisplay.Text, newStart);

            byte[] codeBytes = new byte[CSharpOrNot.Width * CSharpOrNot.Height];
            CSharpOrNot.RenderTextBlockToGreyscaleBytes(this.code, cursorPos, CSharpOrNot.Size, codeBytes);
            this.codeWindow.Text = string.Join(Environment.NewLine,
                                               codeBytes.Select(b => b == 255 ? ' ' : (char)b)
                                               .Batch(CSharpOrNot.Width)
                                               .Select(line => new string(line.ToArray())));

            BitmapTools.ToBitmap(codeBytes, this.renderTarget);
            BitmapTools.Upscale(this.renderTarget, this.output);

            this.codeImage.Source?.Dispose();
            this.output.Save("code.png", ImageFormat.Png);
            this.codeImage.Source = new Avalonia.Media.Imaging.Bitmap("code.png");

            ndarray @in = GreyscaleImageBytesToNumPy(codeBytes, imageCount: 1,
                                                     width: CSharpOrNot.Width, height: CSharpOrNot.Height);
            var    prediction     = this.model.predict(@in);
            int    extensionIndex = (int)prediction.argmax();
            string extension      = IncludeExtensions[extensionIndex].Substring(1);
            bool   csharp         = extension == "cs";

            this.language.Text          = csharp ? "C#" : $"Not C#! ({extension}?)";
            this.languageBox.Background = csharp ? Brushes.Green : Brushes.Red;
        }
Пример #2
0
        public CSharpOrNotWindow()
        {
            this.InitializeComponent();
#if DEBUG
            this.AttachDevTools();
#endif
            this.codeDisplay = this.Get <TextBox>("CodeDisplay");
            this.codeDisplay.PropertyChanged += this.CodeDisplayOnPropertyChanged;

            this.codeWindow     = this.Get <TextBlock>("CodeWindow");
            this.language       = this.Get <TextBlock>("Language");
            this.languageBox    = this.Get <ContentControl>("LanguageBox");
            this.codeImage      = this.Get <Image>("CodeImage");
            this.openFileButton = this.Get <Button>("OpenFileButton");

            BitmapTools.SetGreyscalePalette(this.renderTarget);
            BitmapTools.SetGreyscalePalette(this.output);

            GradientSetup.EnsureInitialized();

            this.model = CreateModel(classCount: IncludeExtensions.Length);
            this.model.build(new TensorShape(null, CSharpOrNot.Height, CSharpOrNot.Width, 1));

            this.LoadWeights();
        }