Spaces:
Sleeping
Sleeping
import os | |
import streamlit as st | |
import google.generativeai as genai | |
secret_key = os.getenv("SECRET_KEY") | |
genai.configure(api_key=secret_key) | |
model=genai.GenerativeModel('gemini-pro') | |
if 'chat' not in st.session_state: | |
st.session_state.chat=model.start_chat(history=[]) | |
st.title('chat with gemini') | |
def role_to_streamlit(role): | |
if role=='model': | |
return 'assistant' | |
else: | |
return role | |
for message in st.session_state.chat.history: | |
with st.chat_message(role_to_streamlit(message.role)): | |
st.markdown(message.parts[0].text) | |
if prompt := st.chat_input('i posses knowledge what do you like to know'): | |
st.chat_message('user').markdown(prompt) | |
response=st.session_state.chat.send_message(prompt) | |
with st.chat_message('assistant'): | |
st.markdown(response.text) |