Spaces:
Sleeping
Sleeping
| import os | |
| import streamlit as st | |
| from langchain.chains import ConversationChain | |
| from langchain_openai import ChatOpenAI | |
| from langchain.memory import ConversationBufferMemory | |
| os.environ["OPENAI_API_KEY"] = "" | |
| # Intialize the chatbot | |
| def init_chatbot(): | |
| memory = ConversationBufferMemory() | |
| chatbot = ConversationChain( | |
| llm =ChatOpenAI(model = "gpt-4o-mini"), | |
| memory = memory, | |
| verbose = False | |
| ) | |
| return chatbot | |
| # Streamlit Application | |
| st.title("Langchain Chatbot") | |
| st.write("Hi, I'm a chatbot built with Langchain powered by GPT. How can I assist you today?") | |
| user_input = st.text_input("You:", placeholder = "Ask me anything....") | |
| if user_input: | |
| with st.spinner("Thinking......"): | |
| resp = chatbot.run(user_input) | |
| st.write(f"Chatbot: {resp}") | |