-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot.py
More file actions
44 lines (32 loc) · 1.09 KB
/
Copy pathchatbot.py
File metadata and controls
44 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from dotenv import load_dotenv
load_dotenv()
import streamlit as st
import os
import google.generativeai as genai;
# Set up API key using environment variable (recommended)
genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
# initialise model
model = genai.GenerativeModel('gemini-pro')
#
chat = model.start_chat(history=[])
def getGeminResponse(question):
response=chat.send_message(question,stream=True)
return response
# initialise streamlit
st.set_page_config(page_title='Gemin')
st.header("GenAi Chatbot")
# initialize session state
if 'chat_history' not in st.session_state:
st.session_state['chat_history'] = []
# inputs
input= st.text_input("Input",key="input")
submit=st.button("Ask Me")
if submit and input:
response=getGeminResponse(input)
# add user query and response to session state
st.session_state['chat_history'].append(("You",input))
for chunk in response:
st.session_state["chat_history"].append(("Bot",chunk.text))
st.subheader("The chat history is")
for role,text in st.session_state['chat_history']:
st.write(f"{role}: {text}")