Docfile commited on
Commit
9b159d4
·
verified ·
1 Parent(s): 0b22f07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -41
app.py CHANGED
@@ -4,6 +4,10 @@ import os
4
  from dotenv import load_dotenv
5
 
6
  load_dotenv()
 
 
 
 
7
  # Configure the API key
8
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
9
 
@@ -14,24 +18,8 @@ safety_settings = [
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-1.5-flash',
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,23 +27,6 @@ def role_to_streamlit(role):
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,12 +59,6 @@ def process_uploaded_file(file):
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:
 
4
  from dotenv import load_dotenv
5
 
6
  load_dotenv()
7
+
8
+
9
+ tools = "google_search_retrieval"
10
+
11
  # Configure the API key
12
  genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
13
 
 
18
  {"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"},
19
  ]
20
 
21
+ model = genai.GenerativeModel('gemini-2.0-flash-exp',
22
+ safety_settings=safety_settings,tools=tools, 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")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  def role_to_streamlit(role):
25
  if role == "model":
 
27
  else:
28
  return role
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  # Add a Gemini Chat history object to Streamlit session state
31
  if "chat" not in st.session_state:
32
  st.session_state.chat = model.start_chat(history=[])
 
59
 
60
  # Accept user's next message, add to context, resubmit context to Gemini
61
  if prompt := st.chat_input("Hey?"):
 
 
 
 
 
 
62
  # Process any uploaded file
63
  uploaded_gemini_file = None
64
  if uploaded_file: