Articles → LANGCHAIN → Create A Simple Chatbot Using Streamlit
Create A Simple Chatbot Using Streamlit
What Is Streamlit?
Library Installations
Langchain
OpenAI
python-dotenv
streamlit
langchain-openai
pip install -r requirements.txt
Create A .ENV File
OPEN_API_KEY="[your_key]"
Program
from langchain_openai import OpenAI
from dotenv import load_dotenv
import streamlit as st
import os
# Load environment variables
load_dotenv()
# Function to load the OpenAI model and get response
def get_openai_response(question):
llm = OpenAI(
api_key=os.getenv("OPEN_API_KEY"),
temperature=0.5
)
response = llm.invoke(question)
return response
# Initialize Streamlit app
st.set_page_config(page_title="Q&A Demo")
st.header("LangChain Application")
user_input = st.text_input("Input: ", key="input")
submit = st.button("Ask the question")
# If ask button is clicked
if submit:
if user_input:
response = get_openai_response(user_input)
st.subheader("The response is")
st.write(response)
else:
st.warning("Please enter a question.")
Output
| Posted By - | Karan Gupta |
| |
| Posted On - | Monday, May 18, 2026 |