Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,41 +72,24 @@ model = genai.GenerativeModel('gemini-1.5-flash',
|
|
| 72 |
st.set_page_config(page_title="Mariam - Assistant IA", page_icon="🤖")
|
| 73 |
st.title("Mariam AI - Chat Intelligent")
|
| 74 |
|
| 75 |
-
#
|
| 76 |
-
if "chat" not in st.session_state:
|
| 77 |
-
st.session_state.chat = model.start_chat(history=[])
|
| 78 |
-
|
| 79 |
-
# CSS personnalisé pour le conteneur d'upload
|
| 80 |
st.markdown("""
|
| 81 |
<style>
|
| 82 |
-
.
|
| 83 |
-
|
| 84 |
-
padding: 0 10px;
|
| 85 |
}
|
| 86 |
.upload-container {
|
| 87 |
display: flex;
|
| 88 |
align-items: center;
|
| 89 |
gap: 10px;
|
| 90 |
-
margin-bottom: 10px;
|
| 91 |
-
}
|
| 92 |
-
.custom-file-upload {
|
| 93 |
-
display: inline-block;
|
| 94 |
-
cursor: pointer;
|
| 95 |
-
}
|
| 96 |
-
.input-container {
|
| 97 |
-
display: flex; /* Utiliser flexbox pour aligner les éléments */
|
| 98 |
-
align-items: center; /* Aligner verticalement les éléments au centre */
|
| 99 |
-
gap: 10px; /* Ajouter un espace entre les éléments */
|
| 100 |
-
}
|
| 101 |
-
.input-container > div {
|
| 102 |
-
flex-grow: 1; /* Permettre à la zone de saisie de prendre l'espace disponible */
|
| 103 |
-
}
|
| 104 |
-
.input-container .st-chat-input {
|
| 105 |
-
flex-grow: 1; /* Permettre à la zone de saisie de prendre l'espace disponible */
|
| 106 |
}
|
| 107 |
</style>
|
| 108 |
""", unsafe_allow_html=True)
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
# Afficher l'historique des messages
|
| 111 |
for message in st.session_state.chat.history:
|
| 112 |
with st.chat_message(role_to_streamlit(message.role)):
|
|
@@ -120,68 +103,38 @@ for message in st.session_state.chat.history:
|
|
| 120 |
input_container = st.container()
|
| 121 |
|
| 122 |
with input_container:
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
with
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
label_visibility="collapsed")
|
| 135 |
-
st.markdown("📁", unsafe_allow_html=True)
|
| 136 |
-
|
| 137 |
-
with col2:
|
| 138 |
-
uploaded_images = st.file_uploader("", type=["jpg", "jpeg", "png", "gif"],
|
| 139 |
-
accept_multiple_files=True, key="images",
|
| 140 |
-
label_visibility="collapsed")
|
| 141 |
-
st.markdown("📸", unsafe_allow_html=True)
|
| 142 |
-
|
| 143 |
-
# Appliquer le style au conteneur
|
| 144 |
-
st.markdown(f"""
|
| 145 |
-
<style>
|
| 146 |
-
div[data-testid='stVerticalBlock']:has(div.uploadedFile) {{
|
| 147 |
-
flex-direction: row !important;
|
| 148 |
-
align-items: center;
|
| 149 |
-
gap: 10px;
|
| 150 |
-
}}
|
| 151 |
-
.stVerticalBlock {{
|
| 152 |
-
gap: 0rem;
|
| 153 |
-
}}
|
| 154 |
-
div[data-testid='stHorizontalBlock'] {{
|
| 155 |
-
align-items: center;
|
| 156 |
-
}}
|
| 157 |
-
div[data-testid='stTextInput'] {{
|
| 158 |
-
padding-bottom: 0;
|
| 159 |
-
}}
|
| 160 |
-
</style>
|
| 161 |
-
""", unsafe_allow_html=True)
|
| 162 |
-
|
| 163 |
if prompt:
|
| 164 |
content = [prompt]
|
| 165 |
temp_files = []
|
| 166 |
|
| 167 |
try:
|
| 168 |
-
# Traitement des
|
| 169 |
-
if uploaded_images:
|
| 170 |
-
for img_file in uploaded_images:
|
| 171 |
-
if allowed_file(img_file.name):
|
| 172 |
-
image = Image.open(img_file)
|
| 173 |
-
content.append(image)
|
| 174 |
-
st.chat_message("user").image(image)
|
| 175 |
-
|
| 176 |
-
# Traitement des autres fichiers
|
| 177 |
if uploaded_files:
|
| 178 |
for file in uploaded_files:
|
| 179 |
if allowed_file(file.name):
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
# Afficher le message utilisateur
|
| 187 |
st.chat_message("user").markdown(prompt)
|
|
|
|
| 72 |
st.set_page_config(page_title="Mariam - Assistant IA", page_icon="🤖")
|
| 73 |
st.title("Mariam AI - Chat Intelligent")
|
| 74 |
|
| 75 |
+
# CSS personnalisé
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
st.markdown("""
|
| 77 |
<style>
|
| 78 |
+
.stFileUploader {
|
| 79 |
+
margin-bottom: 10px;
|
|
|
|
| 80 |
}
|
| 81 |
.upload-container {
|
| 82 |
display: flex;
|
| 83 |
align-items: center;
|
| 84 |
gap: 10px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
}
|
| 86 |
</style>
|
| 87 |
""", unsafe_allow_html=True)
|
| 88 |
|
| 89 |
+
# Initialiser l'historique de chat
|
| 90 |
+
if "chat" not in st.session_state:
|
| 91 |
+
st.session_state.chat = model.start_chat(history=[])
|
| 92 |
+
|
| 93 |
# Afficher l'historique des messages
|
| 94 |
for message in st.session_state.chat.history:
|
| 95 |
with st.chat_message(role_to_streamlit(message.role)):
|
|
|
|
| 103 |
input_container = st.container()
|
| 104 |
|
| 105 |
with input_container:
|
| 106 |
+
col1, col2 = st.columns([0.85, 0.15])
|
| 107 |
+
|
| 108 |
+
with col1:
|
| 109 |
+
prompt = st.chat_input("Que puis-je faire pour vous ?")
|
| 110 |
+
|
| 111 |
+
with col2:
|
| 112 |
+
# Upload unique pour tous les types de fichiers
|
| 113 |
+
uploaded_files = st.file_uploader("📁",
|
| 114 |
+
type=["txt","mp4","mp3","pdf", "jpg", "jpeg", "png", "gif"],
|
| 115 |
+
accept_multiple_files=True)
|
| 116 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
if prompt:
|
| 118 |
content = [prompt]
|
| 119 |
temp_files = []
|
| 120 |
|
| 121 |
try:
|
| 122 |
+
# Traitement des fichiers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
if uploaded_files:
|
| 124 |
for file in uploaded_files:
|
| 125 |
if allowed_file(file.name):
|
| 126 |
+
# Si c'est une image
|
| 127 |
+
if file.type.startswith('image/'):
|
| 128 |
+
image = Image.open(file)
|
| 129 |
+
content.append(image)
|
| 130 |
+
st.chat_message("user").image(image)
|
| 131 |
+
else:
|
| 132 |
+
# Pour les autres types de fichiers
|
| 133 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(file.name)[1]) as temp_file:
|
| 134 |
+
temp_file.write(file.getvalue())
|
| 135 |
+
temp_files.append(temp_file.name)
|
| 136 |
+
uploaded_file = upload_and_process_file(temp_file.name)
|
| 137 |
+
content.append(uploaded_file)
|
| 138 |
|
| 139 |
# Afficher le message utilisateur
|
| 140 |
st.chat_message("user").markdown(prompt)
|