In the era of Artificial Intelligence, large language models are the key to automatically creating content, communicating with humans, and solving complex problems smartly. Among the strong models is Qwen 2.5 32B, a highly powerful AI model with 32 billion parameters, developed by Alibaba’s DAMO Academy. It is famous for generating high-quality content, reasoning effectively, and comprehending context. Qwen 2.5 32B is taking AI capabilities to new levels. This article discusses how Qwen 2.5 32B and LangChain collaborate to transform AI applications, their features, strengths, and how they function in real life, and why they matter as part of artificial intelligence.
This article was published as a part of the Data Science Blogathon.
Qwen 2.5 32B is a large language model developed by Alibaba’s DAMO Academy. It is part of the Qwen series, known for its powerful natural language understanding and generation capabilities. With 32 billion parameters, this model is designed to handle a wide range of AI tasks, including:
Qwen 2.5 32B is optimized for high-quality text generation, making it a great choice for applications that require human-like fluency and context awareness.
LangChain is an AI framework that helps developers build applications using large language models (LLMs) like Qwen 2.5 32B. It provides tools to:
By combining LangChain with Qwen 2.5 32B, businesses can build advanced AI applications that rewrite sentences, generate prompts, simplify text, and improve writing quality.
Effective communication is a critical challenge for individuals and businesses alike. Poorly structured sentences, complex jargon, and unclear prompts often lead to misunderstandings, inefficiencies, and low-quality AI-generated outputs. Whether it’s writing professional emails, generating precise AI prompts, or simplifying technical content, users often struggle to express their thoughts in a clear, structured, and impactful manner.
This AI-powered app solve this problem by enhancing text clarity, optimizing AI prompt generation, and simplifying complex content:
The Text Improvement App follows a streamlined workflow in Streamlit to enhance user input efficiently. The process begins when the user selects the app and inputs text for improvement. Upon clicking the process button, the system loads the ChatGroq LLM model and determines the appropriate processing logic based on the selected functionality—whether rewriting sentences, generating image and video prompts, or simplifying text. Each processing logic is executed accordingly, utilizing LLMChain to generate refined outputs. Finally, the improved text is displayed within the Streamlit interface, ensuring a seamless and user-friendly experience.
Below we will walk through setting up an AI-powered text improvement app using Streamlit and LangChain. From environment setup to processing user inputs, follow these steps to build an intuitive and efficient text enhancement tool.
Create a virtual environment using python -m venv env
and activate it based on your operating system (Windows or macOS/Linux).
# Create a Environment
python -m venv env
# Activate it on Windows
.\env\Scripts\activate
# Activate in MacOS/Linux
source env/bin/activate
Install all required packages by running pip install -r requirements.txt
from the provided GitHub link.
pip install -r https://raw.githubusercontent.com/Gouravlohar/rewriter/refs/heads/main/requirements.txt
Obtain an API key from Groq and store it in the .env
file as API_KEY="Your API KEY PASTE HERE"
.
Visit Groq for API Key.
Paste the API key in .env File
API_KEY="Your API KEY PASTE HERE"
Import essential libraries such as os
, streamlit
, PromptTemplate
, LLMChain
, and ChatGroq
for AI-based text processing.
import os
import streamlit as st
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain_groq import ChatGroq
from dotenv import load_dotenv
Load the API key from the .env
file using load_dotenv()
and validate its existence before proceeding with the app execution.
load_dotenv()
groq_api_key = os.getenv("API_KEY")
if not groq_api_key:
st.error("Groq API Key not found in .env file")
st.stop()
We load the API key from a .env file and ensure it is available before running the app
Design the interface with a sidebar that allows users to select from three functionalities: Rewrite Sentence, Image & Video Prompt Generator, or Text Simplifier.
App Selection Sidebar
st.title("Text Improvement App")
st.sidebar.header("Select App")
st.sidebar.markdown("Choose the functionality you'd like to use:")
app_choice = st.sidebar.selectbox("Choose an App", options=[
"Rewrite Sentence",
"Image and Video Prompt Generator",
"Text Simplifier"
])
Set up structured prompts for different functionalities, including tone adjustments, dialect variations, and creative text transformation.
rewrite_template = """
Below is a draft text that may need improvement.
Your goal is to:
- Edit the draft for clarity and readability.
- Adjust the tone as specified.
- Adapt the text to the requested dialect.
**Tone Examples:**
- **Formal:** "Greetings! Elon Musk has announced a new innovation at Tesla, revolutionizing the electric vehicle industry. After extensive research and development, this breakthrough aims to enhance sustainability and efficiency. We look forward to seeing its impact on the market."
- **Informal:** "Hey everyone! Huge news—Elon Musk just dropped a game-changing update at Tesla! After loads of work behind the scenes, this new tech is set to make EVs even better. Can’t wait to see how it shakes things up!"
**Dialect Differences:**
- **American English:** French fries, apartment, garbage, cookie, parking lot
- **British English:** Chips, flat, rubbish, biscuit, car park
- **Australian English:** Hot chips, unit, rubbish, biscuit, car park
- **Canadian English:** French fries, apartment, garbage, cookie, parking lot
- **Indian English:** Finger chips, flat, dustbin, biscuit, parking space
Start with a warm introduction if needed.
**Draft Text, Tone, and Dialect:**
- **Draft:** {draft}
- **Tone:** {tone}
- **Dialect:** {dialect}
**Your {dialect} Response:**
"""
prompt_generator_template = """
Below is a sentence written in poor English:
"{poor_sentence}"
Your task is to generate a creative writing prompt that improves clarity, grammar, and engagement.
"""
image_video_template = """
Below is a sentence:
"{sentence}"
Your task is to generate a detailed and descriptive prompt optimized for text-to-image or text-to-video generation.
The prompt should be vivid and visually-oriented to help generate high-quality media content.
"""
text_simplifier_template = """
Below is a piece of complex text:
"{complex_text}"
Your task is to rewrite this text in simpler and clearer language while preserving its original meaning.
"""
Initialize the ChatGroq AI model with Qwen-2.5-32B
, enabling real-time text processing with streaming=True
.
def load_LLM(groq_api_key):
"""Loads the ChatGroq model for processing."""
llm = ChatGroq(groq_api_key=groq_api_key, model_name="qwen-2.5-32b", streaming=True)
return llm
Based on the selected feature, prompt users to enter text, select tone and dialect (for rewriting), or provide descriptive inputs for image/video generation.
st.header(f"{app_choice}")
st.markdown("Provide the required inputs below:")
with st.container():
if app_choice == "Rewrite Sentence":
draft = st.text_area("Draft Text", height=200, placeholder="Enter your text here...")
col1, col2 = st.columns(2)
with col1:
tone = st.selectbox("Select desired tone", options=["Formal", "Informal"])
with col2:
dialect = st.selectbox("Select dialect", options=[
"American English",
"British English",
"Australian English",
"Canadian English",
"Indian English"
])
Dynamically adjust the input fields based on the chosen functionality, ensuring a user-friendly and adaptable interface.
elif app_choice == "Image and Video Prompt Generator":
sentence = st.text_area("Sentence", height=200, placeholder="Enter a sentence describing your desired media...")
elif app_choice == "Text Simplifier":
complex_text = st.text_area("Complex Text", height=200, placeholder="Enter the complex text here...")
When the “Process” button is clicked, load the AI model, apply the relevant logic using LLMChain
, and display the refined output in Streamlit.
if st.button("Process"):
with st.spinner("Processing your text..."):
llm = load_LLM(groq_api_key)
if app_choice == "Rewrite Sentence":
prompt_obj = PromptTemplate(input_variables=["tone", "dialect", "draft"], template=rewrite_template)
chain = LLMChain(llm=llm, prompt=prompt_obj)
result = chain.run(draft=draft, tone=tone, dialect=dialect)
elif app_choice == "Image and Video Prompt Generator":
prompt_obj = PromptTemplate(input_variables=["sentence"], template=image_video_template)
chain = LLMChain(llm=llm, prompt=prompt_obj)
result = chain.run(sentence=sentence)
elif app_choice == "Text Simplifier":
prompt_obj = PromptTemplate(input_variables=["complex_text"], template=text_simplifier_template)
chain = LLMChain(llm=llm, prompt=prompt_obj)
result = chain.run(complex_text=complex_text)
st.markdown("### Output:")
st.markdown(result)
Based on the selected feature, it:
Get Full Code on GitHub Here.
Rewrite Sentence Input
Yo, I’ve been grinding non-stop and bringing the heat, so I think it’s time we talk cash. I was hoping for a fatter paycheck—just wanna make sure my hustle and skills ain’t going unnoticed. Think we can make this work?
Rewrite Sentence Output
Image and Video Prompt Generator Input
A futuristic city with flying cars and neon lights.
Image and Video Prompt Generator Output
Text Simplifier Input
In recent years, the exponential advancements in artificial intelligence and machine learning algorithms have not only enhanced the efficiency of data processing and predictive analytics but have also introduced unprecedented challenges in ethical decision-making, data privacy, and algorithmic bias, necessitating a multidisciplinary approach that integrates computational sciences, legal frameworks, and ethical considerations to ensure the responsible deployment of AI-driven technologies across diverse sectors, including healthcare, finance, and autonomous systems.
Text Simplifier Output
The Text Improvement App is a powerful AI-driven tool designed to refine text clarity, creativity, and readability. Developed with Streamlit and LangChain, it offers features like sentence rewriting, AI-ready prompt generation, and text simplification. Powered by Groq’s Qwen-2.5-32B model, it ensures high-quality, real-time text conversion, making it an essential tool for professionals, students, and content creators. Future upgrades, including voice command and multi-language support, will further enhance its role in building a writing assistant, making it even more versatile and efficient. With these advancements, the app continues to push the boundaries of building a writing assistant for diverse user needs.
A. The app helps users enhance text clarity, generate creative prompts for media, and simplify complex sentences using AI.
A. It refines text by improving grammar, readability, and tone. Users can also select a preferred dialect for localization.
A. Yes, the Image and Video Prompt Generator converts simple sentences into detailed prompts optimized for AI-generated media.
A. Absolutely! It simplifies difficult sentences while preserving meaning, making content more accessible.
A. The app is powered by Groq’s Qwen-2.5-32B model, which provides high-quality text processing and content generation.
The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.