Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,17 @@ import PIL.Image
|
|
| 3 |
import os
|
| 4 |
import google.generativeai as genai
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# Configuration de la page
|
| 7 |
st.set_page_config(
|
| 8 |
page_title="Mariam Anglais",
|
|
@@ -62,6 +73,72 @@ st.markdown(
|
|
| 62 |
unsafe_allow_html=True
|
| 63 |
)
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
# Configuration de l'API Google Generative AI
|
| 66 |
GOOGLE_API_KEY = st.secrets["GOOGLE_API_KEY"] # Définir le chemin d'accès dans les secrets de l'application
|
| 67 |
genai.configure(api_key=GOOGLE_API_KEY)
|
|
@@ -108,14 +185,14 @@ with col2:
|
|
| 108 |
# Section de choix du type d'analyse
|
| 109 |
st.subheader("🎛️ Choix du type d'analyse")
|
| 110 |
analysis_type = st.radio("",
|
| 111 |
-
("🔍 Type 1: Analyse de
|
| 112 |
|
| 113 |
# Description des types d'analyse (cachée par défaut, visible en cliquant)
|
| 114 |
with st.expander("ℹ️ En savoir plus sur les types d'analyse"):
|
| 115 |
-
if analysis_type == "🔍 Type 1: Analyse de
|
| 116 |
-
st.write("
|
| 117 |
else:
|
| 118 |
-
st.write("
|
| 119 |
|
| 120 |
# Bouton de soumission
|
| 121 |
if st.button("🚀 Soumettre", key="submit"):
|
|
@@ -133,14 +210,13 @@ with col2:
|
|
| 133 |
st.stop()
|
| 134 |
|
| 135 |
# Définir le prompt en fonction du type d'analyse
|
| 136 |
-
if analysis_type == "🔍 Type 1: Analyse de
|
| 137 |
-
prompt =
|
| 138 |
else:
|
| 139 |
-
prompt =
|
| 140 |
-
|
| 141 |
# Appel de l'API Google Generative AI
|
| 142 |
try:
|
| 143 |
-
model = genai.GenerativeModel(model_name="gemini-2.0-flash-exp")
|
| 144 |
with st.spinner("Analyse en cours..."):
|
| 145 |
progress_bar = st.progress(0)
|
| 146 |
response = model.generate_content([prompt] + image_parts, stream=True)
|
|
@@ -159,4 +235,4 @@ with col2:
|
|
| 159 |
|
| 160 |
# Pied de page
|
| 161 |
st.markdown("---")
|
| 162 |
-
st.write("© 2024 Mariam
|
|
|
|
| 3 |
import os
|
| 4 |
import google.generativeai as genai
|
| 5 |
|
| 6 |
+
|
| 7 |
+
safety_settings = [
|
| 8 |
+
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
|
| 9 |
+
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
|
| 10 |
+
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
|
| 11 |
+
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"},
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
# Configuration de la page
|
| 18 |
st.set_page_config(
|
| 19 |
page_title="Mariam Anglais",
|
|
|
|
| 73 |
unsafe_allow_html=True
|
| 74 |
)
|
| 75 |
|
| 76 |
+
prompt_text = """
|
| 77 |
+
je souhaite faire mon travail d'anglais qui consiste à de l'analyse de texte. j'aimerais que tu le phase en respectant scrupuleusement la méthodologie suivante. j'aimerais que tu fasses ce travail en anglais en donnant également la traduction française:
|
| 78 |
+
|
| 79 |
+
INTRODUCTION
|
| 80 |
+
|
| 81 |
+
SUMMARY
|
| 82 |
+
|
| 83 |
+
COMMENTARY
|
| 84 |
+
|
| 85 |
+
EVALUATION
|
| 86 |
+
|
| 87 |
+
I- INTRODUCTION
|
| 88 |
+
|
| 89 |
+
Title (what is the title of the text?)
|
| 90 |
+
|
| 91 |
+
Nature (what is it?)
|
| 92 |
+
|
| 93 |
+
Author (who wrote it?)
|
| 94 |
+
|
| 95 |
+
Origin (where was it extracted?)
|
| 96 |
+
|
| 97 |
+
Date of publication (when was it written?)
|
| 98 |
+
|
| 99 |
+
Genre (descriptive...)
|
| 100 |
+
|
| 101 |
+
General idea (what is it about?)
|
| 102 |
+
|
| 103 |
+
Writer' intention (what for?)
|
| 104 |
+
|
| 105 |
+
II - SUMMARY
|
| 106 |
+
|
| 107 |
+
The components (the structure / text subdivision)
|
| 108 |
+
(The main parts of the text and their ideas)
|
| 109 |
+
|
| 110 |
+
The summary itself.
|
| 111 |
+
|
| 112 |
+
III - COMMENTARY
|
| 113 |
+
|
| 114 |
+
Focus on the main points of interest from the summary
|
| 115 |
+
|
| 116 |
+
Discuss, explain and develop the main points of the writer's opinion, deal with them in a coherent and logical order.
|
| 117 |
+
|
| 118 |
+
Tone
|
| 119 |
+
|
| 120 |
+
Style
|
| 121 |
+
|
| 122 |
+
IV-EVALUATION
|
| 123 |
+
|
| 124 |
+
Assess the text value
|
| 125 |
+
|
| 126 |
+
The interest of the text
|
| 127 |
+
|
| 128 |
+
The lessons, you've learnt and the impact on your opinion.
|
| 129 |
+
|
| 130 |
+
V - BRANCHING OUT
|
| 131 |
+
|
| 132 |
+
Personal opinion (give one's opinion)
|
| 133 |
+
|
| 134 |
+
Feelings (I had mixed feeling about.........)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
"""
|
| 138 |
+
|
| 139 |
+
prompt_image = " Décris l'image "
|
| 140 |
+
|
| 141 |
+
|
| 142 |
# Configuration de l'API Google Generative AI
|
| 143 |
GOOGLE_API_KEY = st.secrets["GOOGLE_API_KEY"] # Définir le chemin d'accès dans les secrets de l'application
|
| 144 |
genai.configure(api_key=GOOGLE_API_KEY)
|
|
|
|
| 185 |
# Section de choix du type d'analyse
|
| 186 |
st.subheader("🎛️ Choix du type d'analyse")
|
| 187 |
analysis_type = st.radio("",
|
| 188 |
+
("🔍 Type 1: Analyse de Texte", "🧠 Type 2: Document iconographique"), label_visibility="collapsed")
|
| 189 |
|
| 190 |
# Description des types d'analyse (cachée par défaut, visible en cliquant)
|
| 191 |
with st.expander("ℹ️ En savoir plus sur les types d'analyse"):
|
| 192 |
+
if analysis_type == "🔍 Type 1: Analyse de texte":
|
| 193 |
+
st.write("il s'agit ici de l'analyse de texte avec (INTRODUCTION,SUMMARY,COMMENTARY,EVALUATION.")
|
| 194 |
else:
|
| 195 |
+
st.write("il s'agit ici du document iconographique.")
|
| 196 |
|
| 197 |
# Bouton de soumission
|
| 198 |
if st.button("🚀 Soumettre", key="submit"):
|
|
|
|
| 210 |
st.stop()
|
| 211 |
|
| 212 |
# Définir le prompt en fonction du type d'analyse
|
| 213 |
+
if analysis_type == "🔍 Type 1: Analyse de Text":
|
| 214 |
+
prompt = prompt_text
|
| 215 |
else:
|
| 216 |
+
prompt = prompt_image
|
|
|
|
| 217 |
# Appel de l'API Google Generative AI
|
| 218 |
try:
|
| 219 |
+
model = genai.GenerativeModel(model_name="gemini-2.0-flash-exp",safety_settings=safety_settings)
|
| 220 |
with st.spinner("Analyse en cours..."):
|
| 221 |
progress_bar = st.progress(0)
|
| 222 |
response = model.generate_content([prompt] + image_parts, stream=True)
|
|
|
|
| 235 |
|
| 236 |
# Pied de page
|
| 237 |
st.markdown("---")
|
| 238 |
+
st.write("© 2024 Mariam AI - Tous droits réservés.")
|