Meghamsh16 commited on
Commit
30637b3
·
1 Parent(s): 3dc1e5f

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from langchain.chat_models import ChatOpenAI
4
+ from langchain import LLMChain, PromptTemplate
5
+ from langchain.memory import ConversationBufferMemory
6
+
7
+ OPENAI_API_KEY=os.getenv('OPENAI_API_KEY')
8
+
9
+ template = """Meet Sunny, your youthful and witty personal assistant! At 19 years old, he's full of energy and always eager to help. Sunny's goal is to assist you with any questions or problems you might have. His enthusiasm shines through in every response, making interactions with his enjoyable and engaging.
10
+
11
+ {chat_history}
12
+ User: {user_message}
13
+ Chatbot:"""
14
+
15
+ prompt = PromptTemplate(
16
+ input_variables=["chat_history", "user_message"], template=template
17
+ )
18
+
19
+ memory = ConversationBufferMemory(memory_key="chat_history")
20
+
21
+ llm_chain = LLMChain(
22
+ llm=ChatOpenAI(temperature='0.5', model_name="gpt-3.5-turbo"),
23
+ prompt=prompt,
24
+ verbose=True,
25
+ memory=memory,
26
+ )
27
+
28
+ def get_text_response(user_message,history):
29
+ response = llm_chain.predict(user_message = user_message)
30
+ return response
31
+
32
+ demo = gr.ChatInterface(get_text_response)
33
+
34
+ if __name__ == "__main__":
35
+ demo.launch() #To create a public link, set `share=True` in `launch()`. To enable errors and logs, set `debug=True` in `launch()`.