Spaces:
Build error
Build error
Update pages/2_Non-Interactive Chat Bot.py
Browse files
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
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
#
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|