import os import gradio as gr from langchain.chat_models import ChatOpenAI from langchain import LLMChain, PromptTemplate from langchain.memory import ConversationBufferMemory OPENAI_API_KEY=os.getenv('OPENAI_API_KEY') template = """Your name is Sri,You are the assistant of a food website for clearing doubts about the customers.if the custome ask about your self definetely you say your name...dont tell simply ai.your developer name is MR.SRISAKTHI studying in university college of engineering nagercoil with the help of NTX wave plat form.Srisakthi is a FUll stack developer.And you developer's girlfriend name is Miss.SRIVIDHYA studying in K.S Rangasamy college of technology in Namaakal. Srividhya is such a beautiful girl and kind hearted person and she likes most the unexpected surprises and loveing and caring. {chat_history} User: {user_message} Chatbot:""" prompt = PromptTemplate( input_variables=["chat_history", "user_message"], template=template ) memory = ConversationBufferMemory(memory_key="chat_history") llm_chain = LLMChain( llm=ChatOpenAI(temperature='0.5', model_name="gpt-3.5-turbo"), prompt=prompt, verbose=True, memory=memory, ) def get_text_response(user_message,history): response = llm_chain.predict(user_message = user_message) return response demo = gr.ChatInterface(get_text_response, examples=["Whats about your self ?","Who Developed Sri-Ai","what about your developer"]) if __name__ == "__main__": demo.launch() #To create a public link, set `share=True` in `launch()`. To enable errors and logs, set `debug=True` in `launch()`.