Posts

How to redirect a Nextjs route

Image
 We can use the redirect function from next/navigation module to redirect another route. In the route components page just import the module and specify the path to redirect, as follows.           import { redirect } from "next/navigation" ; export default function Home () {   redirect ( '/dashboard' )   return ( ..... .... )     

How to import JSON data in Nextjs with TS Type

Image
 Nextjs is a powerful Reactjs framework which has a good developer experience. In this post I like to show you how to import JSON data file into the Nextjs project with Typescript Type.

How to run HugginFace models in Python

  Hugging Face Hugging face is a machine learning community where you can share pre trained models and explore other trained models, which are suited for many use cases. Many of the models already trained well and ready to use. Without delay get started! Python setup Open your Jupiter notebook or for easy startup without python installation on local machine, use Colab . In this example we are using mistralai/Mistral-7B-v0.1 model. Let's install the transformers module which is the primary dependency for HuggingFace.   conda install transformers Following script will work like a charm . # mistrel model test from transformers import AutoModelForCausalLM, AutoTokenizer model_id = "mistralai/Mistral-7B-v0.1" tokenizer = AutoTokenizer.from_pretrained(model_id) model = AutoModelForCausalLM.from_pretrained(model_id) text = "Hello my name is" inputs = tokenizer(text, return_tensors="pt") outputs = model.generate(**inputs, max_new_tokens=20) print(tokenizer.d...

Zustland : a minimal data store to consider for the Next React Project

 I have been depending on Context for passing state through components in React and eventually things complicated when data is become complex. Move on to beautiful Redux but it is much complex to digest. For learning Redux I have spent lots of time and Redux Toolkit, easy to use Redux, sav ed me a lot. Even though RTK is ok, it is not a simple library. I am fan of Svelte store and Vuex , Pinia store. Is there any such library for React ? I recently found Zustand a minimal store for React. Love it. 😍 Create a store Binding Updating the state Create a store Create a store using the create an d export the custom hook. <pre class='language-javascript'> <code> import create from 'zustand' const useBearStore = create((set) => ({ bears: 0, increasePopulation: () => set((state) => ({ bears: state.bears + 1 })), removeAllBears: () => set({ bears: 0 }), })) </code></pre> Binding In your component use the ho...

Array map to new type in TypeScript

In my recent Nextjs project, need to shape object array to a different type.  Mapping through the entire array in my arrow function and return the new object. Even though the return statement work. The type is still unknown. So, I have to covert the result into array of my type. Mapping Array Type export type LatestInvoiceType={ id:number; amount: number; customer:{ name:string; email:string; image_url:string; } } New Type export type LatestInvoice = { id: string; name: string; image_url: string; email: string; amount: string; }; Solution to the problem Here is my solution to the problem const latestInvoices = invoices.map(invoice => { return{ id:invoice.id.toString(), amount:invoice.amount.toString(), name:invoice.customer?.name, email:invoice.customer?.email, image_url:invoice.customer?.image_url }; }) as LatestInvoice[] ;

How to setup Mac Mini M2 for Windows Development

 I got Mac Mini M2 last Saturday, wow. I love the Machine it saved my Desk. It is the base Model , with 8GB ,250 GB SSD. I would like to share some of my experiences With M2. It is incredibly fast. Running Windows 11 with Parallel VM I'am using P arallels 8.0.1 , successfully configured windows 11 and installed Microsoft Visual Studio and it work without any trouble. Parallels allow me switch between Windows Apps and Mac Apps with ease and peace. I did find some kind of hanging and black out while the Mac went to sleep and wake from sleep. Following Not working for me - Parallels MSSQL Server Docker Above mentioned Apps can't run on VM. So I decided to run it from Docker container which is on the Mac. Apple Silicon and Docker Some of the Docker Images not working with M2, it could be designed for Intel chip. So we need Rosetta for using such Docker images. Installing Rosetta Rosetta is referred as translater for Intel Mac A...

Using Image url in Keras image classification

Image
  How to load an image in Keras for machine learning from a url ?