Posts

Factory Pattern in C#: Simplifying Object Creation

Image
The Factory Pattern is one of the creational design patterns used in software development. It helps in managing the object creation process by abstracting it from the client code. Instead of instantiating objects directly in the client code, the Factory Pattern allows the client to request objects without needing to know the exact class type or logic behind the object creation. This results in more maintainable, flexible, and scalable code. The Problem Without Factory Pattern Before diving into the Factory Pattern, let’s first see what happens without it. Code Example: namespace factoryPatternexample { public interface IMobile { string GetCPU(); string GetRAM(); } } namespace factoryPatternexample { public class ApplePhone : IMobile { public string GetCPU() { return "Apple CPU"; } public string GetRAM() { return "8GB"; } } } namespac

Understanding the Singleton Design Pattern in C#

Image
The Singleton design pattern is one of the most widely used creational design patterns. It ensures that a class has only one instance while providing a global point of access to it. This is particularly useful when exactly one object is needed to coordinate actions across the system. In this blog post, we will explore the Singleton pattern in C#, understand why it’s useful, and review various implementations including thread safety and the usage of the Lazy<T> class. We will also look at how each of these approaches works with example code. Why Use the Singleton Pattern?   The primary purpose of the Singleton pattern is to control object creation by limiting the number of instances to just one. Some of the common use cases include: Configuration management: A centralized configuration object that needs to be accessed across different parts of the application. Logging: Logging systems should have a single instance for maintaining a consistent log throughout the application. Cachi

I have created an application to extract text from image using AI

Image
 In this article, I am going to demonstrate how text is getting extracted from image file using Gemini AI model. Also, will explain how the application is developed with the help of chat GPT and some custom code.     Very first i gone to chatGPT application and added below prompts so that my application structure i can get the application code to start with. Following is the screenshot of the prompt i have written and answer given by chatGPT.    I have copied the code given by chat gpt and modified as per my requirement that means i got 70 to 80 percentage code to develop the application. Following are the Prerequisites required for development of this application : Visual studio code Python Api Key of Gemini can be obtain from https://aistudio.google.com    Open visual studio code and create the file with name " imagetextextractapp .py". Now in visual studio code and go to terminal menu and click on New terminal link it will open new terminal. In terminal enter below comm

Create Chat bot application using Python, Streamlit and Gemini AI

Image
In this article I am going to explain creating chat bot application using Python, Streamlit library and Gemini AI. In this chat bot application application will be self host with specific port on computer ad can be accessible from browser.     following Prerequisites required for development of this application : Visual studio code Python Api Key of Gemini can be obtain from https://aistudio.google.com    Open visual studio code and create the file with name "chatbot.py". Now in visual studio code and go to terminal menu and click on New terminal link it will open new terminal. In terminal enter below command to install the Google generative AI library and steamlit library in your machine.   pip install google-generativeai langchain-google-genai streamlit   Now copy below code and paste in the " chatbot .py" file. import streamlit as st import google.generativeai as genai genai.configure(api_key="enter your key obtain from aistudio.google.com&quo

Query your own documents with LlamaIndex and Gemini

Image
In this article I am going to explain about on creating application for indexing and querying your own documents using LlamaIndex and Gemini. I will provide step by step guide to create application in python.   Prerequisites for this example is as follows: Visual studio code Python Api Key of Gemini can be obtain from https://aistudio.google.com    Open visual studio code and create the file with name "demo.py". Now in visual studio code and go to terminal menu and click on New terminal link it will open new terminal. In terminal enter below command to install the LlamaIndex library and LlamaIndex gemini library in your machine. pip install llama-index llama-index-llms-gemini llama-index-embeddings-gemini Create the folder named "doc" in root directory of the application as shown in below image and store the documents you want to query.       Now copy below code and paste in the "demo.py" file. from llama_index.embeddings.gemini import GeminiEmbedd