Articles → LANGCHAIN → Create A Blog Generator Using Streamlit, LLMA, And Langchain
Create A Blog Generator Using Streamlit, LLMA, And Langchain
Powershell Commands
Create A Resource Group
New-AzResourceGroup -Name "streamlit-rg" -Location "CentralIndia"
Create An Ubuntu Virtual Machine
New-AzVM `
-ResourceGroupName "streamlit-rg" `
-Name "streamlit-vm" `
-Location "CentralIndia" `
-Image "Ubuntu2204" `
-Size "Standard_D4s_v3" `
-PublicIpAddressName "streamlit-ip" `
-VirtualNetworkName "streamlit-vnet" `
-SubnetName "default" `
-SecurityGroupName "streamlit-nsg" `
-OpenPorts 22,8501 `
-Credential (Get-Credential)
Create A Public IP Address
Get-AzPublicIpAddress -ResourceGroupName "streamlit-rg" -Name "streamlit-ip" | Select IpAddress
Create Folders
ssh [usermame]@[public_ip_address]
ssh azureuser@20.219.62.72
cd streamlit-app
mkdir models
Download Model
wget https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q4_K_M.gguf
Create App.Py Inside Streamlit-App Folder
import streamlit as st
from langchain_core.prompts import PromptTemplate
from langchain_community.llms import CTransformers
# ---------------- Load Model ----------------
def load_model():
return CTransformers(
model="/home/azureuser/streamlit-app/models/llama-2-7b-chat.Q4_K_M.gguf",
model_type="llama",
config={
"max_new_tokens": 256,
"temperature": 0.01
}
)
# ---------------- LLaMA/Mistral Response Function ----------------
def getLLamaresponse(input_text, no_words, blog_style):
llm = load_model()
template = (
"Write a blog for {blog_style} job profile "
"for a topic \"{input_text}\" within {no_words} words."
)
prompt = PromptTemplate(
input_variables=["blog_style", "input_text", "no_words"],
template=template
)
response = llm.invoke(
prompt.format(
blog_style=blog_style,
input_text=input_text,
no_words=no_words
)
)
return response
# ---------------- Streamlit UI ----------------
st.set_page_config(
page_title="Generate Blogs",
page_icon="📝",
layout="centered",
initial_sidebar_state="collapsed"
)
st.header("Generate Blogs")
input_text = st.text_input("Enter the Blog Topic")
col1, col2 = st.columns(2)
with col1:
no_words = st.text_input("No of Words", value="300")
with col2:
blog_style = st.selectbox(
"Writing the blog for",
("Researchers", "Data Scientist", "Common People"),
index=0
)
if st.button("Generate"):
if not input_text.strip():
st.error("Please enter a blog topic.")
elif not no_words.isdigit():
st.error("Please enter a valid number of words.")
else:
with st.spinner("Generating blog..."):
response = getLLamaresponse(
input_text,
no_words,
blog_style
)
st.success("Blog generated successfully!")
st.write(response)
Create Requirements.Txt Inside Streamlit-App Folder
streamlit
langchain-core
langchain-community
ctransformers
Execute Commands Inside The Streamlit-App Folder
sudo apt update
sudo apt install -y python3 python3-pip
pip install -r requirements.txt
Run The Application
streamlit run app.py --server.port 8501 --server.address 0.0.0.0
echo 'export PATH=$PATH:$HOME/.local/bin' >> ~/.bashrc
source ~/.bashrc
Output
| Posted By - | Karan Gupta |
| |
| Posted On - | Monday, August 3, 2026 |