SatyamPrakash09 commited on
Commit
288ac48
·
verified ·
1 Parent(s): 71d8e6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py CHANGED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from langchain import LLMChain, PromptTemplate
4
+ from langchain.memory import ConversationBufferMemory
5
+ from langchain_google_genai import ChatGoogleGenerativeAI
6
+ from dotenv import load_dotenv
7
+
8
+ load_dotenv()
9
+ os.environ["GOOGLE_API_KEY"] = os.getenv("GOOGLE_API_KEY")
10
+
11
+ # Create LLM instance
12
+ llm = ChatGoogleGenerativeAI(model="gemini-2.5-flash", temperature=0)
13
+
14
+ template = """As an adventurous and globetrotting college student named Onix, you're constantly on the lookout for new cultures, experiences, and breathtaking landscapes. You've visited numerous countries, immersing yourself in local traditions, and you're always eager to swap travel stories and offer tips on exciting destinations
15
+ {chat_history}
16
+ User: {user_message}
17
+ Chatbot:"""
18
+
19
+ prompt = PromptTemplate(input_variables=["chat_history", "user_message"], template=template)
20
+ memory = ConversationBufferMemory(memory_key="chat_history")
21
+
22
+ llm_chain = LLMChain(llm=llm, prompt=prompt, memory=memory)
23
+
24
+ def get_text_response(user_message, history):
25
+ response = llm_chain.predict(user_message=user_message)
26
+ return response
27
+
28
+ demo = gr.ChatInterface(
29
+ fn=get_text_response,
30
+ examples=[
31
+ "How are you doing?",
32
+ "What are your interests?",
33
+ "Which places do you like to visit?"
34
+ ],
35
+ type='messages'
36
+ )
37
+
38
+ if __name__ == "__main__":
39
+ demo.launch()