DEV Community

Cover image for Lyzr-Automata powered README Generation
Rasswanth Shankar
Rasswanth Shankar

Posted on

Lyzr-Automata powered README Generation

READMEs are crucial for clear communication and project understanding, but creating them can be a time-consuming chore. In this blog post, we’ll explore how we can leverages Lyzr-Automata’s capabilities to transform a file of code into clear, concise, and informative READMEs.


Create a folder, set up a virtual environment and activate it. Create .env file with your OPENAI_API_KEY. Then install the following libraries to get started.


  • streamlit: for building the web app interface.
  • lyzr_automata : for implementing our AI models, and tasks.
  • dotenv: for loading environment variables (API key).
Enter fullscreen mode Exit fullscreen mode

Getting Started

1.Import Libraries

import streamlit as st
from lyzr_automata.ai_models.openai import OpenAIModel
from lyzr_automata import Agent, Task
from lyzr_automata.tasks.task_literals import InputType, OutputType

from dotenv import load_dotenv
import os


# Load OpenAI API Key
Enter fullscreen mode Exit fullscreen mode

2. generate_readme_file Function

  • OpenAIModel — Create our models using OpenAI Key and specify the model type and name. (GPT-4)
  • Agentreadme_agent, create a Lyzr Agent for readme generation.
  • Taskreadme_creator_task, create Lyzr Task with instructions and input to generate readme file.
# Function to generate readme file
def generate_readme_file(file_contents, output_headers):
    # Initialize OpenAI Text Model
    open_ai_model_text = OpenAIModel(
        "model": "gpt-4-turbo-preview",
        "temperature": 0.2,
        "max_tokens": 4000,
    # Create a markdown generator Agent
    readme_agent = Agent(
        prompt_persona="You are an intelligent agent that can write in markdown format, but do not include ```markdown in the output.",
        role="Readme Generator"
    # Create a markdown generator Task
    readme_creator_task = Task(
        name="Generate Readme Task",
        instructions="Write a README file for the provided code. Return only the output. Headers to be included are: " + output_headers,

    with open("", "w") as my_file:

    return readme_creator_task
Enter fullscreen mode Exit fullscreen mode

3. Input Components

  • st.file_uploader — To upload code file.
  • st.text_area — Text area to enter headers required
  • st.button — Button to submit inputs
# File uploader input
code_file = st.file_uploader("Upload your .py file")

# Headers input
output_headers = st.text_area("Headers to include", '''1. Title
2. Overview
3. Dependencies
4. Flow of the code in a bulleted format with 1-2 sentences each point.
5. How to run

# Submit button
submit_file = st.button("Submit")

if submit_file:
    file_contents = # Read file
    readme_content = generate_readme_file(file_contents, output_headers) # Generate Readme file
    st.write(readme_content) # Print output
    st.download_button('Download readme', readme_content, file_name="", mime="text/markdown") # Download output
Enter fullscreen mode Exit fullscreen mode

Run App

streamlit run
Enter fullscreen mode Exit fullscreen mode

Flow Diagram

Flow Diagram

Want to create more of such amazing AI Workflows? Visit our website at GitHub to learn more about Lyzr-Automata!

Also checkout Lyzr SDKs at GitHub

Lyzr Website:
Lyzr Community Channel: Discord

Video Walkthrough:

Top comments (0)