LangChain_Demo / app.py
jchen8000's picture
Create app.py
908889a verified
raw
history blame
952 Bytes
import gradio as gr
from langchain.chains import ConversationChain
from langchain.memory import ConversationBufferMemory
from langchain.llms import Groq
# Initialize the language model and memory
llm = Groq(api_key="your_groq_api_key")
memory = ConversationBufferMemory()
# Define the conversation chain
conversation = ConversationChain(llm=llm, memory=memory)
# Function to generate responses
def generate_response(user_input):
response = conversation.run(user_input)
return response
# Define additional inputs and examples if needed
additional_inputs = []
example1 = []
# Create the Gradio interface
interface = gr.ChatInterface(
fn=generate_response,
theme="Nymbo/Alyx_Theme",
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
additional_inputs=additional_inputs,
examples=example1,
cache_examples=False,
)
# Launch the app
interface.launch()