Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,9 +14,24 @@ safety_settings = [
|
|
14 |
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"},
|
15 |
]
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
def role_to_streamlit(role):
|
22 |
if role == "model":
|
@@ -24,6 +39,23 @@ def role_to_streamlit(role):
|
|
24 |
else:
|
25 |
return role
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
# Add a Gemini Chat history object to Streamlit session state
|
28 |
if "chat" not in st.session_state:
|
29 |
st.session_state.chat = model.start_chat(history=[])
|
@@ -56,6 +88,12 @@ def process_uploaded_file(file):
|
|
56 |
|
57 |
# Accept user's next message, add to context, resubmit context to Gemini
|
58 |
if prompt := st.chat_input("Hey?"):
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
# Process any uploaded file
|
60 |
uploaded_gemini_file = None
|
61 |
if uploaded_file:
|
|
|
14 |
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"},
|
15 |
]
|
16 |
|
17 |
+
def create_model_with_search(use_search):
|
18 |
+
"""
|
19 |
+
Crée un modèle Gemini avec ou sans recherche Google
|
20 |
+
|
21 |
+
Args:
|
22 |
+
use_search (bool): Active ou désactive la recherche Google
|
23 |
+
|
24 |
+
Returns:
|
25 |
+
genai.GenerativeModel: Modèle Gemini configuré
|
26 |
+
"""
|
27 |
+
tools = "google_search_retrieval" if use_search else None
|
28 |
+
|
29 |
+
return genai.GenerativeModel(
|
30 |
+
'gemini-2.0-flash-exp',
|
31 |
+
safety_settings=safety_settings,
|
32 |
+
system_instruction="Tu es un assistant intelligent. ton but est d'assister au mieux que tu peux. tu as été créé par Aenir et tu t'appelles Mariam",
|
33 |
+
tools=tools
|
34 |
+
)
|
35 |
|
36 |
def role_to_streamlit(role):
|
37 |
if role == "model":
|
|
|
39 |
else:
|
40 |
return role
|
41 |
|
42 |
+
# Ajouter un radiobox pour la recherche Google
|
43 |
+
st.sidebar.header("Paramètres de recherche")
|
44 |
+
use_google_search = st.sidebar.radio(
|
45 |
+
"Recherche Google",
|
46 |
+
options=[
|
47 |
+
"Désactivée",
|
48 |
+
"Activée"
|
49 |
+
],
|
50 |
+
index=0 # Par défaut, recherche désactivée
|
51 |
+
)
|
52 |
+
|
53 |
+
# Convertir le radiobox en booléen
|
54 |
+
search_enabled = use_google_search == "Activée"
|
55 |
+
|
56 |
+
# Créer le modèle initial avec les paramètres du radiobox
|
57 |
+
model = create_model_with_search(search_enabled)
|
58 |
+
|
59 |
# Add a Gemini Chat history object to Streamlit session state
|
60 |
if "chat" not in st.session_state:
|
61 |
st.session_state.chat = model.start_chat(history=[])
|
|
|
88 |
|
89 |
# Accept user's next message, add to context, resubmit context to Gemini
|
90 |
if prompt := st.chat_input("Hey?"):
|
91 |
+
# Recréer le modèle avec les paramètres de recherche actuels
|
92 |
+
model = create_model_with_search(search_enabled)
|
93 |
+
|
94 |
+
# Réinitialiser la conversation avec le nouveau modèle
|
95 |
+
st.session_state.chat = model.start_chat(history=st.session_state.chat.history)
|
96 |
+
|
97 |
# Process any uploaded file
|
98 |
uploaded_gemini_file = None
|
99 |
if uploaded_file:
|