TensorFlow.js : unable to find content for text generation using models like gpt2 in nodejs

I m new to ML or AI, just started learning

so my task is to make chatbot using models(locally in our system for data privacy) like gpt2 or any other that present on internet and then fine tune them by our own dataset. so it can perform according to our requirement. in NODEJS OR javascript(NO PYTHON).

So, till now i have gone through tensorflowJS docs and accordingly i have downloaded LLM model locally in system like gpt2(.h5 format) and then converted it into TF.JS format(.json and .bin files) and now want to perform text generation but unable to find any code or content for the same.

Now, my first QUESTON:- is it possible to perform text generation or make chatbot from locally models and then finetunning in nodejs or javascript(no python) using tensorflow.js or not

if its possible, then tell me next steps or any way or any resources or any library other than tensorflowJS to make this work done…

OR USING PYTHON IS ONLY SOLUTION???…

How do I disable the dot that appears on a line series chart on hover? I am using ‘lightweight-charts’ with react

I am trying to disable this dot that appears on the line chart on hover.
Attached Screenshot

I referred the lightweight chart docs and couldn’t find anything related to this. This is my code for the chart initialisation.

this.chartContainerRef = chartContainerRef;
    this.chart = createChart(this.chartContainerRef.current, {
      layout: {
        background: { type: ColorType.Solid, color: backgroundColor },
        textColor,
      },
      width: this.chartContainerRef.current.clientWidth,
      height: Math.max(this.chartContainerRef.current.clientHeight - 72, 0),
      handleScroll: false,
      handleScale: false,
      grid: {
        vertLines: {
          visible: false,
        },
        horzLines: {
          visible: false,
        },
      },
      crosshair: {
        vertLine: {
          visible: false,
          labelVisible: false, // Add this line to disable the vertical crosshair label
        },
        horzLine: {
          visible: false,
          labelVisible: false, // Add this line to disable the horizontal crosshair label
        },
      },
    });
    this.chart.timeScale().fitContent();
    this.chart.timeScale().applyOptions({
      rightOffset: 100,
      secondsVisible: true,
      timeVisible: true,
    });
    this.series = this.chart.addAreaSeries({
      lineColor,
      topColor: areaTopColor,
      bottomColor: areaBottomColor,
      lastPriceAnimation: 2,
      priceFormat: {
        // TODO: Infer precision from dataset
        precision: 6,
        minMove: 0.000001,
      },
    });

How to insert a dynamic component inside a element in Angular

Imagine we have a html structure as follows

<div [innerHTML]="contentFromAPI | safeHTML"></div>

Now the content from the api would be a string consists of more HTML elements. Making the structure something like this:

<div [innerHTML]="contentFromAPI | safeHTML">
 <p></p>
 <p></p>
 <p></p>
 <p></p>
 <p></p>
 <p></p>
 <p></p>
 <p></p>
 <p></p>
 <p></p>
</div>

I want to create a component dynamically and insert it at the middle of the child nodes. In this case at the 5th place.

For this I’m doing something like this:

html file:

<div [innerHTML]="contentFromAPI | safeHTML" #articleContent></div>

ts file:

@ViewChild('articleContent', { read: ViewContainerRef })
  private articleContent!: ViewContainerRef;

ngOnChanges(){
 if(ads){
   this.addElementToTemplate();
 }
}

private addElementToTemplate() {
setTimeout(() => {
      const childrenLength =
        this.articleContent.element.nativeElement.children.length;
        this.articleContent.createComponent(DynamicElement,{index: Math.ceil(childrenLength/2)});
    }, 3000);
}

but this adds the component as a sibling to content element. Something like this:

<div [innerHTML]="contentFromAPI | safeHTML">
     <p></p>
     <p></p>
     <p></p>
     <p></p>
     <p></p>
     <p></p>
     <p></p>
     <p></p>
     <p></p>
     <p></p>
</div>
<dynamic-element></dynamic-element>

TinyMCE doesn’t save to database, toolbar doesn’t show

I am trying to use TinyMCE on ASP.NET MVC and whenever I try to save any text inside the TinyMCE textbox, it doesn’t save any of it, but the button works and it saves any text that’s inside a different text box rather than TinyMCE.

This is what I currently have:

<script type="text/javascript">
    tinymce.init({
        selector: '#richtexteditor',
        height: 350,
        content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }',
        license_key: 'gpl',
        promotion: false,
        branding: false
    });



</script>

@Html.EditorFor(model => model.Content, new { htmlAttributes = new { @class = "form-control", @id = "richtexteditor" } })

-it’s in a partial web view and I have everything working besides the saving and the toolbar not showing. I played around with it, and it seemed like the toolbar is showing up behind the partial view which kind of makes it seem like it’s not working. I was wondering how I would come around to fixing both of these problems.

I also found out that TinyMCE just replaces my original text box with it’s own, and exposing that textbox via devtools and writing any text into it makes that text save into the database. But, not the one written inside TinyMCE’s built-in textbox. I am using MVC along with N tier architecture, maybe TinyMCE has some limitations with it? I’d like some ideas and suggestions.

I also found out that TinyMCE just replaces my original text box with it’s own, and exposing that textbox via devtools and writing any text into it makes that text save into the database. But, not the one written inside TinyMCE’s built-in textbox. I am using MVC along with N tier architecture, maybe TinyMCE has some limitations with it? I’d like some ideas and suggestions.

Next.js 14, Tesseract.js Error: cannot find module …/.next/worker-script/node/index.js’

I am trying to extract text from the image with tesseract.js node module, i am working with nextjs 14. even though i have install the tesseract.js module i get error that module not find when i try to extract i get this error:

Error: Cannot find module '...(projectdirectory)/.next/worker-script/node/index.js'
    at Module._resolveFilename (node:internal/modules/cjs/loader:1142:15)
    at Module._load (node:internal/modules/cjs/loader:983:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
    at MessagePort.<anonymous> (node:internal/main/worker_thread:186:26)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:822:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28) {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

it should look into the node modules not in .next
so for that i try to change the path of worker-sript in my file

const worker = await createWorker('eng',1,{workerPath: "./node_modules/tesseract.js/src/worker-script/node/index.js"});

but after changing the path there another error get thrown that is:

TypeError: fetch is not a function

i dont know why its happening… from my side everthing is fine, everthing works in my project execpt this.. function

i try to change the path of worker module here is the code :

import {createWorker} from 'tesseract.js';

export const imgToText = async () =>{
      //const converter = await createWorker('eng')
      const worker = await createWorker('eng',1,{workerPath: "./node_modules/tesseract.js/src/worker-script/node/index.js"});
      try {
            const img = "/fake.png"
            const text = await worker.recognize(img);
            console.log(text.data.text);
            return text.data.text;
      } catch (error) {
            console.log("image extraction error", error);
            throw error;
      } finally {
            await worker.terminate();
      }
}

i expect text from the image here.

but i got the fetch is not a function so i try to install the node-fetch module but it also didnt worked.

thank you!

Tinymce fontsizeinput default value

Look at: https://codepen.io/pennan88/pen/zYXRdbO

  1. Use TinyMCE 7.0.0
  2. Create a minimal Editor using toolbar = ‘fontsizeinput’
  3. Define, even it is regarding to the documentation the default, font_size_input_default_unit:'pt'.

Problem

When setting font_size_input_default_unit: "pt" even if it’s the default value, the input-box still displays px. So if i set the font-size to 11 pt, it gets displayed as 14.6667px.


Expected result

I’d expect the input-box to display the unit Npt, where N is any number.


Tested on

  • Browser: Edge, latest version
  • OS: Windows 11
  • TinyMCE version: 7.0.0 and 6.8.1
  • Environment:
    • Local computer, running Blazor WASM
    • NET7.0
    • TinyMCE.Blazor with <script src="_content/TinyMCE.Blazor/tinymce-blazor.js"></script> or
    • TinyMCE.Blazor and TinyMCE which downloads a local lib with the files

In some cases, “this” in the function passed as an argument to the higher order function is Window or undefined. Please tell me the difference [duplicate]

class Foo {
  
  m(f) {
    f();
  }
}
let foo = new Foo();


foo.m(function () {
  console.log(this);
  // Window
});
class Foo {
  
  m(f) {
    f();
  }
}

class Boo {
 
  m2() {
    let foo = new Foo();

    foo.m(function () {
      console.log(this);
      // undefined
    });
  }
}
let boo = new Boo();
boo.m2();

Why are the two results different?

I think this should be undefined in both because they are called in a function format rather than an object calling them in a method format like o.method(). If Window is calling it implicitly, why is the second code undefined?

I looked up lexical context and execution, but it was too difficult to understand.

In the case of arrow functions, it was possible to predict what “this” would be, but in the case of anonymous functions, it was not possible to predict.

Cant convert from BSON to MongoDB date type

I’m trying to filter some data stored in MongoDB using parameters contained in the URL.

The issue arises when the request is sent, causing the server to crash with the following error:

can't convert from BSON type string to Date

I attempted to resolve this problem by changing the type of the variables to Number, hoping it would fix the issue, but encountered the same result. Below is the code I’m using to send the request to the server:

For example, in the case the form is submitted with values year=2021, month=11 I just want the third object to be returned.

Can anyone help me solve the problem?

Thank you in advance for your patience!

Intl.Collator sorting in Node, Chrome, Webkit, Firefox and Postgres Collation differences

I am comparing the collation of Intl.Collator in the three browsers, Node and Postgres Collation and realized that the order of most implementations are very different. The only two implementations matching each other for the locale ‘en’ are Chrome and Firefox. For example the letters from MATHEMATICAL SANS-SERIF ITALIC SMALL A to Z are sorted together with the letters a - z in Intl with locales as e.g. en in Chrome and Firefox but not in Postgres. I was thinking that all implementations are based on the same CLDR data. The differences between the implementations are (Tested with Selenium):

Chrome - Node 1474
Chrome - Webkit 34727
Chrome - Firefox 0
Chrome - Postgres 25781
Webkit - Node 34727
Webkit - Postgres 34727
Node   - Postgres 34892

A more predictable sort order would enable to sort agnostic in the frontend and backend.

“user denied geolocation” in leaflet/leaflet-locatecontrol on some (mobile) devices/not asking for permissions

I am using leaflet 1.9.4 and leaflet-locatecontrol 0.79. My code is as follows:

function initmap() {
    // initialize map
    map = new L.Map('map', {
        tap: false,
        center: [52.520803, 13.40945],
        zoom: 17
    });

    const osmUrl='https://tile.openstreetmap.org/{z}/{x}/{y}.png';

    const osm = new L.TileLayer(
        osmUrl, {
            minZoom: 12,
            maxZoom: 28,
            maxNativeZoom: 19,
            useCache: true,
            crossOrigin: true }
    );

    // show OSM
    map.addLayer(osm);
    
    // create locate controls
    var lc = L.control.locate({
        setView: 'always',
        keepCurrentZoomLevel: true,
        locateOptions: {
            timeout: 30000,
            enableHighAccuracy: true
        },
        onLocationError: onLocationError,
        strings: {
            title: "follow"
        }
    }).addTo(map);
    
    // start Geolocation
    lc.start();

    // if geolocation fails, show error and set view to default
    function onLocationError(e) {
        alert(e.message);
        map.setView([52.520803, 13.40945]), 17);
    }

While the code seems to work as expected on most devices (f. e. Chrome 123 on Android 14, Firefox on Android 9, Opera on iOS), it fails in some constellations (f. e. Chrome 123 on Android 9 or Safari on iOS – same devices which work well with firefox or opera).

The expected behavior is, that the browser asks the user for permission to use geolocation and start geolocating him afterwards with updating the map to the users position. Instead it doesn’t ask whether geolocation should be allowed and I get the alert immediatley, that the “user denied geolocation”.

All browsers have the permission to use location services and the website is accessed via https.

Syncing Data Transfer Between S3 Buckets Using AWS SDK and Temporal SDK”

able to transfer data from s3 source bucket to s3 destination bucket and its work in sync way like when ever the source get update i should send automatically that date to the destination bucket and if any error happens in the get or in the post it do the process until it finish the task so I want to complete this without use of any AWS paid service and “temporal sdk” I am using it if there is any other way please help to solve this problem preferred programming language is nodejs

temporal configuration code with setup explanation or any other technology which can able to solve the problem with nodejs

MUI Grid layout with info on the left and an image just to the right

Given the following React MUI V5 sample code, I am setting up a profile page where I have the details of a person to the left of the page that is represented with a label/value down the lefthand side of the page.

What I am unsure how to do, is place that “IMAGE” entry (please assume that this is a profile image of size (width: 300px and height: 300px) to the right of the values, that is alongside the label/values rows, but not right-most, just nicely positioned to the right of the info.

At the same time, I do not want any row info on the left to have any gaps inorder to accomodate the image, just to the right.

import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Grid';

const Item = styled(Paper)(({ theme }) => ({
  backgroundColor: theme.palette.mode === 'dark' ? '#1A2027' : '#fff',
  ...theme.typography.body2,
  padding: theme.spacing(1),
  textAlign: 'center',
  color: theme.palette.text.secondary,
}));

export default function NestedGrid() {
  return (
    <Box sx={{ flexGrow: 1 }}>
      <Grid container spacing={1}>
        <Grid item xs={2}>
          <Box>Username:</Box>
        </Grid>
        <Grid item xs={6}>
          <Box>Qwerty</Box>
        </Grid>
        <Grid item xs={4}></Grid>

        {/* First Name */}
        <Grid item xs={2}>
          <Box>First Name:</Box>
        </Grid>
        <Grid item xs={6}>
          <Box>Bob</Box>
        </Grid>
        <Grid item xs={4}></Grid>

        {/* Surname */}
        <Grid item xs={2}>
          <Box>Surname:</Box>
        </Grid>
        <Grid item xs={6}>
          <Box>Hope</Box>
        </Grid>
        <Grid item xs={4}></Grid>

        {/* DOB */}
        <Grid item xs={2}>
          <Box>DOB:</Box>
        </Grid>
        <Grid item xs={6}>
          <Box>01/01/2022</Box>
        </Grid>
        <Grid item xs={4}></Grid>

        {/* Occupation */}
        <Grid item xs={2}>
          <Box>Occupation:</Box>
        </Grid>
        <Grid item xs={6}>
          <Box>IT</Box>
        </Grid>
        <Grid item xs={4}></Grid>

        {/* Status */}
        <Grid item xs={2}>
          <Box>Status:</Box>
        </Grid>
        <Grid item xs={6}>
          <Box>Married</Box>
        </Grid>
        <Grid item xs={4}></Grid>

        {/* Image */}
        <Grid item xs={2}></Grid>
        <Grid
          item
          xs={6}
          style={{ display: 'inline-flex', alignItems: 'center' }}
        >
          <Box>IMAGE</Box>
        </Grid>
        <Grid item xs={4}></Grid>
      </Grid>
    </Box>
  );
}

Display the second text after finishing printing the first text

I want the first text to be printed first, and then after finishing printing the first text; The second text will start to be printed.

In the code I wrote, the first text is printed well, but the second text is not printed for me.

Also, I tried hard to apply a sign (|) while printing each word to convey the feeling of typing to the user, but I couldn’t make it work. Please guide me in this matter as well.

My codes:

const text1 = "Your first sentence here"; // Enter your first sentence here
const text2 = "Your second sentence here"; // Enter your second sentence here

let i = 0;
let isFinished = false;

function typeSentence(text, element) {
    const interval = setInterval(() => {
        if (i === text.length) {
            clearInterval(interval);
            isFinished = true;

            if (element === $('#loading-text')) {
                // Check if the first sentence is finished
                if (isFinished) {
                    // Start typing the second sentence after finishing the first sentence
                    i = 0;
                    typeSentence(text2, $('#loading-text2'));
                }
            }
        } else {
            element.text(element.text() + text[i]);
            i++;
        }
    }, 100); // Speed of animation (adjust as needed)
}

typeSentence(text1, $('#loading-text'));
 #loading-text, #loading-text2 {
            font-size: 24px;
            font-weight: bold;
            text-align: center;
            margin: 20px auto;
            width: 50%;
            opacity: 1;
        }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<div id="loading-text"></div>
<div id="loading-text2"></div>

How to add filter on parent div using in react js?

I have testData array, Now I’m adding filter, this is working fine but inside the box only like if there is display: "N" then the object should not be display, this is working fine but there is a issue like if there is all the objects with display: "N" inside types[] array then parent-wrapper div should not display.

Code:-

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://unpkg.com/react@18/umd/react.development.js" crossorigin></script>
  <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" crossorigin></script>
  <script src="https://unpkg.com/@babel/[email protected]/babel.min.js" crossorigin></script>
</head>

<body>
  <div id="root"></div>

  <script type="text/babel" data-presets="react,stage-3">
    const Example = () => {
     
       const testData = [
    {
        name: "Wrapper One",
        types: [
            {
                id: "0",
                type: "Type One",
                display: "Y"
            },
            {
                id: "2",
                type: "Type Two",
                display: "N"
            },
        ]
    },
    {
        name: "Wrapper Two",
        types: [
          {
            id: "0",
            type: "Type One",
            display: "N"
        },
        ]
    },
]
     
      return (
        <div>
         {testData?.map((ele: any, index: any) => (
    <div key={index} className="parent-wrapper" style={{background:'gray', marginBottom:'20px'}}>
      <h1>{ele.name}</h1>
    {ele.types.map((data: any, index: number) => (
                <div key={index}>
                  {(data?.display === "Y") ?
                  <p>{data.type}</p>
                  : null}
                </div>
     ))}
     </div>
     ))}
        </div>
      );
    };
    const root = ReactDOM.createRoot(document.getElementById("root"))
    root.render(<Example />);
  </script>
</body>

</html>

Thanks for your efforts!

what is wrong with my code: javascript onclick image change image

I’d like to change my image onClick but have the new image get larger with transform

Another thing I’d like to do is I’d like to hide other divs simultaneously when I click this one

function changeImage() {
  var image = document.getElementById("myDIV");
  if (image.src.match("dot")) {
    image.src = "";
    else {
      image.src = "";
    }
  }
}

function myFunction() {
  document.getElementById("myDIV").style.Transform = "scale(2)";
}
<div id="myDIV" onclick="changeImage()"><img src=""></div>