AjayKr09 commited on
Commit
63b0800
·
verified ·
1 Parent(s): 9587725

Update pages/2_Non-Interactive Chat Bot.py

Browse files
Files changed (1) hide show
  1. pages/2_Non-Interactive Chat Bot.py +33 -30
pages/2_Non-Interactive Chat Bot.py CHANGED
@@ -1,30 +1,33 @@
1
- import streamlit as st
2
- import os
3
- from langchain_google_genai import ChatGoogleGenerativeAI
4
- from langchain_core.prompts import ChatPromptTemplate
5
-
6
- # Set GOOGLE_API_KEY
7
- os.environ['GOOGLE_API_KEY'] = 'AIzaSyBHPIIk4-BOgXvnQ2_o6c2wTGpY2ByRIDs'
8
-
9
- st.title("Non-Interactive Chat Bot")
10
-
11
- model_gemini = ChatGoogleGenerativeAI(
12
- model='gemini-pro',
13
- temperature=0,
14
- max_output_tokens=500,
15
- convert_system_message_to_human=True
16
- )
17
-
18
- # Assuming model_gemini is defined correctly elsewhere
19
- prompt = ChatPromptTemplate.from_template("{content}")
20
- chain = prompt | model_gemini
21
-
22
- input_text = st.text_area('Ask your Question :', height=100)
23
-
24
- # Add a button to trigger the chatbot response
25
- if st.button('Submit'):
26
- # Invoke the chain with input text
27
- response = chain.invoke({'content': input_text})
28
-
29
- # Display response on the Streamlit web interface
30
- st.write(response.content)
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from langchain_google_genai import ChatGoogleGenerativeAI
4
+ from langchain_core.prompts import ChatPromptTemplate
5
+
6
+ # Set your Gemini API key from environment variables
7
+ gemini_api_key = os.getenv("GEMINI_API_KEY")
8
+
9
+ # Initialize the Gemini API-powered chatbot model
10
+ model_gemini = ChatGoogleGenerativeAI(
11
+ model='gemini-pro',
12
+ temperature=0,
13
+ max_output_tokens=500,
14
+ convert_system_message_to_human=True
15
+ )
16
+
17
+ # Create a chat prompt template
18
+ prompt = ChatPromptTemplate.from_template("{content}")
19
+ chain = prompt | model_gemini
20
+
21
+ # Streamlit app title
22
+ st.title("Non-Interactive Chat Bot")
23
+
24
+ # Text area for user input
25
+ input_text = st.text_area('Ask your Question :', height=100)
26
+
27
+ # Button to submit user query
28
+ if st.button('Submit'):
29
+ # Invoke the chain with user input text
30
+ response = chain.invoke({'content': input_text})
31
+
32
+ # Display the chatbot response
33
+ st.write(response.content)