Poetry Generator with FastAPI and GoogleAI

code: gitHub

Building a Poetry Generator with FastAPI and GoogleAI

I’m excited to share a recent project I completed: a poetry generator using FastAPI and the GoogleAI. By leveraging Large Language Models (LLMs), I created a web service that generates beautiful poems based on user input. Let’s dive into the exciting world of AI-powered creativity!

What Are Large Language Models?

Large Language Models (LLMs) are a type of artificial intelligence designed to understand and generate human-like text. They are trained on vast amounts of text data and can perform various tasks, including translation, summarization, and creative writing. The GoogleAI library we’ll use in this project harnesses the power of these models to generate poems.

Project Overview

In this project, I created:

  • Set up the environment and dependencies.
  • Create a GoogleAI class to interact with the Google Generative AI model.
  • Build a FastAPI application to handle user input and generate poems.
  • Develop a user-friendly frontend to display the poems.

Creating the GoogleAI Class

The GoogleAI class will manage interactions with the Google Generative AI model. This class will include methods for generating loading messages and poems.

Building the FastAPI Application

I used FastAPI to create a web service that handles user input and interacts with the GoogleAI class.

Setting Up FastAPI

Created an app.py file and set up the FastAPI application:

Handling User Input

POST route to generate poems based on user input:

This function receives the user’s input, generates a poem using the GoogleAI instance, and returns the poem along with a loading message.

Developing the Frontend

The frontend consists of an HTML file for structure, a CSS file for styling, and a JavaScript file for interactivity.

HTML (index.html)

CSS (styles.css)

JavaScript (script.js)

Conclusion

This project demonstrates the power of Large Language Models (LLMs) in creating unique and inspiring content. By integrating FastAPI with GoogleAI, we can build a web service that brings the beauty of poetry to users with just a few clicks.

Feel free to explore the full code on GitHub and try it out yourself! Let your creativity soar with the help of AI.

AI is revolutionizing the way we create and interact with content. Whether it’s generating poetry, writing stories, or composing music, the possibilities are endless. I hope this project inspires you to delve deeper into the world of AI and unleash your creativity in new and exciting ways.

Design a site like this with WordPress.com
Get started