Ashkchamp commited on
Commit
798e85c
·
verified ·
1 Parent(s): 2bdf755

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +56 -0
  2. requirements.txt +16 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from langchain_core.prompts import ChatPromptTemplate
4
+ from langchain_core.output_parsers import StrOutputParser
5
+ from langchain_google_genai import ChatGoogleGenerativeAI
6
+ from langchain_core.messages import HumanMessage, SystemMessage
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+
11
+
12
+ os.environ["GOOGLE_API_KEY"] = os.getenv('api')
13
+
14
+
15
+ system_template = "You are a helpful assistant. Please response to the user queries"
16
+ prompt_template = ChatPromptTemplate.from_messages([
17
+ ('system', system_template),
18
+ ('user', 'Question:{question}')
19
+ ])
20
+
21
+
22
+ model = ChatGoogleGenerativeAI(model="gemini-pro", convert_system_message_to_human=True)
23
+ parser = StrOutputParser()
24
+ chain = prompt_template | model | parser
25
+
26
+ st.title("LangChain Chatbot Demo")
27
+ st.markdown("""
28
+ Welcome to the LangChain Chatbot Demo!
29
+ Type your query below and get responses powered by Google's Generative AI.
30
+ """)
31
+ st.sidebar.header("Chatbot Settings")
32
+ st.sidebar.text("You can enter your query in the main section below.")
33
+
34
+ input_text = st.text_input("Enter your question:", "")
35
+
36
+
37
+ if input_text:
38
+ try:
39
+ with st.spinner('Generating response...'):
40
+ response = chain.invoke({"question": input_text})
41
+ st.write("**Chatbot Response:**")
42
+ st.write(response)
43
+
44
+ if "history" not in st.session_state:
45
+ st.session_state.history = []
46
+ st.session_state.history.append({"role": "user", "text": input_text})
47
+ st.session_state.history.append({"role": "chatbot", "text": response})
48
+
49
+ except Exception as e:
50
+ st.error(f"An error occurred: {e}")
51
+
52
+ st.sidebar.header("Conversation History")
53
+ if "history" in st.session_state and st.session_state.history:
54
+ for message in st.session_state.history:
55
+ role = "You" if message["role"] == "user" else "Chatbot"
56
+ st.sidebar.write(f"**{role}:** {message['text']}")
requirements.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ langchain
2
+ langchain_core
3
+ python-dotenv
4
+ streamlit
5
+ langchain_community
6
+ langchain_google_genai
7
+ langserve
8
+ uvicorn
9
+ sse_starlette
10
+ fastapi
11
+ langchain-groq
12
+ wikipedia
13
+ arxiv
14
+ langchainhub
15
+ sentence_transformers
16
+ langchain-objectbox