Update 1_Gemini_Pro.py
Browse files- 1_Gemini_Pro.py +7 -5
1_Gemini_Pro.py
CHANGED
|
@@ -1,10 +1,8 @@
|
|
| 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(
|
|
@@ -56,7 +54,8 @@ if "app_key" in st.session_state:
|
|
| 56 |
message_placeholder.markdown("Thinking...")
|
| 57 |
try:
|
| 58 |
full_response = ""
|
| 59 |
-
|
|
|
|
| 60 |
word_count = 0
|
| 61 |
random_int = random.randint(5, 10)
|
| 62 |
for word in chunk.text:
|
|
@@ -68,8 +67,11 @@ if "app_key" in st.session_state:
|
|
| 68 |
word_count = 0
|
| 69 |
random_int = random.randint(5, 10)
|
| 70 |
message_placeholder.markdown(full_response)
|
|
|
|
| 71 |
except genai.types.generation_types.BlockedPromptException as e:
|
| 72 |
-
st.
|
|
|
|
| 73 |
except Exception as e:
|
| 74 |
st.exception(e)
|
|
|
|
| 75 |
st.session_state.history = chat.history
|
|
|
|
|
|
|
|
|
|
| 1 |
import google.generativeai as genai
|
| 2 |
+
from google.generativeai import SafetySettings
|
| 3 |
import streamlit as st
|
| 4 |
import time
|
| 5 |
import random
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
st.set_page_config(
|
|
|
|
| 54 |
message_placeholder.markdown("Thinking...")
|
| 55 |
try:
|
| 56 |
full_response = ""
|
| 57 |
+
safety_settings = SafetySettings(max_tokens=2048)
|
| 58 |
+
for chunk in chat.send_message(prompt, stream=True, safety_settings=safety_settings):
|
| 59 |
word_count = 0
|
| 60 |
random_int = random.randint(5, 10)
|
| 61 |
for word in chunk.text:
|
|
|
|
| 67 |
word_count = 0
|
| 68 |
random_int = random.randint(5, 10)
|
| 69 |
message_placeholder.markdown(full_response)
|
| 70 |
+
|
| 71 |
except genai.types.generation_types.BlockedPromptException as e:
|
| 72 |
+
st.error("Sorry, I cannot generate unsafe content")
|
| 73 |
+
|
| 74 |
except Exception as e:
|
| 75 |
st.exception(e)
|
| 76 |
+
|
| 77 |
st.session_state.history = chat.history
|