Building applications would be no good if it solved no societal problems. My country boasts of over 250 tribes with 500 dialects. Despite the beauty in its diversity, there seems to be a communication problem experienced while relating with others from different tribes and cultures. This strengthened my decision to build this tool.
In this article, I will describe the tool in detail, its capabilities and the Artificial intelligence behind it, Also, some areas of improvement will be recommended as it’s a work in progress.
Intro to MyLang
MyLang is a web application powered by the use of artificial intelligence large language models (LLM) to aid the easy expression of oneself in local languages at one’s convenience. It provides an easy-to-use web user interface where one can prompt the tool with phrases and sentences of varying lengths to aid your language needs. For now, it offers this translation feature for the 3 major languages spoken nationwide with opportunities to increase coverage of other languages and dialects as artificial intelligence advances.
The framework behind the application
The Artificial intelligence serving as the backbone for this application is Gemini. This is an artificial language learning model built and maintained by Google. It provides free multiple AI features including text, images and audio capabilities. With this, it aids user search for information. It also has integrations with the popular programming languages and frameworks.
Subsequently, we will be walking through the code process with that I used to build the application.
The building process
First of all, this project backend was built using Node JS express framework as it’s a tool I'm very comfortable with and also due to it's easy of integration with 3rd party packages.
To begin, I generated a Google API key from the Google MakerSuite. The link to this can be found here.
Thereafter, I created a Node JS app to execute the project.
This can be achieved by having Node JS installed on the personal computer and then running npm init
in the folder of choice. The Express packages can then be installed by executing the npm install express
command.
To integrate Node JS to Google Gemini’s AI, the Google generative AI npm
package seems to suffice. More info regarding integrating the package can be found on the Google Gemini documentation page .
Thereafter, I created a .env
file to store my API secret key and prevent it from being exposed in my code base. The dotenv
package was also installed to allow easy access of the API key stored in the .env
file to the index.js
file. Thereafter, we will proceed with creating the relevant code endpoint.
In the project, to ensure its simplicity, we created a single API endpoint to integrate it with the front end.
app.get("/google-ai", async (req, res) => {
const model = genAI.getGenerativeModel({
model: "Gemini-1.5-flash"
});
const prompt = help translate only(no interpretation) this to ${req.body.lang} $ {
req.body.text
}
const result = await model.generateContent(prompt);
const response = await result.response;
const text = response.text();
res.status(200).json(text);
console.log(text)
})
The endpoint is accessible via the GET request to the Google AI endpoint.
In this endpoint, the Google generative model
is initialized and activated. The latest model is the Gemini 1.5 flash model. Thereafter, the definitive prompt for the project was typed out. The language of choice is also inserted into the prompt. The prompt is executed and the response from the AI model is then sent to the user.
Navigating to the endpoint executes the code above and then outputs our results.
here is the full backend code for the project.
const express = require("express");
const { GoogleGenerativeAI } = require("@google/generative-ai");
const dotenv = require("dotenv");
const app = express();
dotenv.config(); // Load environment variables
app.use(express.json()); // Middleware to parse JSON bodies
console.log(process.env); // Log environment variables for debugging
// Initialize Google Generative AI with the API key from environment variables
const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);
app.get("/", (req, res) => {
res.send("Hello, World");
});
app.get("/google-ai", async (req, res) => {
try {
// Get the model
const model = genAI.getGenerativeModel({ model: "Gemini-1.5-flash" });
// Create the prompt
const prompt = `help translate only (no interpretation) this to ${req.body.lang}: ${req.body.text}`;
// Generate content
const result = await model.generateContent({ prompt });
// Get the response text
const response = await result.response;
const text = response.text();
// Send the response
res.status(200).json(text);
console.log(text);
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Internal Server E
We also built a simple frontend web application in React-Vite to consume the API we built. Here is a link to the frontend repo.
Users can have access to the functional application here.
The code repository for the entire code project can also be found here.
Areas of improvement
In subsequent periods, I hope to implement a text-to-voice feature for this application.
I also intend to integrate it with other local language-based LLMs to include more dialects.
Converting soft copy documents to other language forms too would be a great addition.
With that, we’ve come to the end of my article. You can also interact with me on my blog and check out my other articles here. Till next time, keep on coding!