Update 1_Gemini_Pro.py
Browse files- 1_Gemini_Pro.py +6 -4
1_Gemini_Pro.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
|
|
|
|
|
| 1 |
import google.generativeai as genai
|
| 2 |
import streamlit as st
|
| 3 |
import time
|
| 4 |
import random
|
| 5 |
-
from utils import
|
| 6 |
|
| 7 |
|
| 8 |
st.set_page_config(
|
|
@@ -37,7 +39,7 @@ with st.sidebar:
|
|
| 37 |
if st.button("Clear Chat Window", use_container_width = True, type="primary"):
|
| 38 |
st.session_state.history = []
|
| 39 |
st.rerun()
|
| 40 |
-
|
| 41 |
for message in chat.history:
|
| 42 |
role = "assistant" if message.role == "model" else message.role
|
| 43 |
with st.chat_message(role):
|
|
@@ -54,7 +56,7 @@ if "app_key" in st.session_state:
|
|
| 54 |
message_placeholder.markdown("Thinking...")
|
| 55 |
try:
|
| 56 |
full_response = ""
|
| 57 |
-
for chunk in chat.send_message(prompt, stream=True, safety_settings =
|
| 58 |
word_count = 0
|
| 59 |
random_int = random.randint(5, 10)
|
| 60 |
for word in chunk.text:
|
|
@@ -70,4 +72,4 @@ if "app_key" in st.session_state:
|
|
| 70 |
st.exception(e)
|
| 71 |
except Exception as e:
|
| 72 |
st.exception(e)
|
| 73 |
-
st.session_state.history = chat.history
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
import google.generativeai as genai
|
| 4 |
import streamlit as st
|
| 5 |
import time
|
| 6 |
import random
|
| 7 |
+
from utils import SAFETY_SETTTINGS
|
| 8 |
|
| 9 |
|
| 10 |
st.set_page_config(
|
|
|
|
| 39 |
if st.button("Clear Chat Window", use_container_width = True, type="primary"):
|
| 40 |
st.session_state.history = []
|
| 41 |
st.rerun()
|
| 42 |
+
|
| 43 |
for message in chat.history:
|
| 44 |
role = "assistant" if message.role == "model" else message.role
|
| 45 |
with st.chat_message(role):
|
|
|
|
| 56 |
message_placeholder.markdown("Thinking...")
|
| 57 |
try:
|
| 58 |
full_response = ""
|
| 59 |
+
for chunk in chat.send_message(prompt, stream=True, safety_settings = SAFETY_SETTTINGS):
|
| 60 |
word_count = 0
|
| 61 |
random_int = random.randint(5, 10)
|
| 62 |
for word in chunk.text:
|
|
|
|
| 72 |
st.exception(e)
|
| 73 |
except Exception as e:
|
| 74 |
st.exception(e)
|
| 75 |
+
st.session_state.history = chat.history
|