Spaces:
Sleeping
Sleeping
Download app.py from FractalStudioMontreal/chat: direct link, hf CLI and curl.
- Browser
- Download file 2.47 kB
-
https://huggingface.co/spaces/FractalStudioMontreal/chat/resolve/main/app.py
- Command line
-
hf download hf://spaces/FractalStudioMontreal/chat/app.py
-
curl -L -o app.py https://huggingface.co/spaces/FractalStudioMontreal/chat/resolve/main/app.py
2.47 kB
| import streamlit as st | |
| # Configuration de la page pour un design minimal | |
| st.set_page_config( | |
| page_title="Chatbot", | |
| layout="centered", | |
| initial_sidebar_state="collapsed" | |
| ) | |
| # CSS personnalisé pour un look plus natif | |
| st.markdown(""" | |
| <style> | |
| /* Fond transparent */ | |
| .stApp { | |
| background: transparent; | |
| } | |
| /* Style des entrées */ | |
| .stTextInput input { | |
| border-radius: 8px; | |
| border: 1px solid #e0e0e0; | |
| padding: 10px; | |
| } | |
| /* Style des boutons */ | |
| .stButton button { | |
| border-radius: 8px; | |
| padding: 10px 20px; | |
| background-color: #007bff; | |
| color: white; | |
| border: none; | |
| } | |
| /* Cache les éléments Streamlit par défaut */ | |
| #MainMenu {visibility: hidden;} | |
| footer {visibility: hidden;} | |
| header {visibility: hidden;} | |
| /* Style des messages */ | |
| .chat-message { | |
| padding: 15px; | |
| border-radius: 10px; | |
| margin: 5px 0; | |
| background-color: #f8f9fa; | |
| } | |
| .user-message { | |
| background-color: #e3f2fd; | |
| } | |
| .bot-message { | |
| background-color: #f5f5f5; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # Interface du chatbot | |
| def main(): | |
| if "messages" not in st.session_state: | |
| st.session_state.messages = [] | |
| # Zone de saisie | |
| with st.container(): | |
| user_input = st.text_input("", placeholder="Posez votre question...", key="user_input") | |
| if st.button("Envoyer", key="send"): | |
| if user_input: | |
| # Ajouter le message de l'utilisateur | |
| st.session_state.messages.append({"role": "user", "content": user_input}) | |
| # Simuler la réponse du bot | |
| response = "Voici la réponse à votre question..." # Remplacer par votre logique de réponse | |
| st.session_state.messages.append({"role": "assistant", "content": response}) | |
| # Affichage des messages | |
| for message in reversed(st.session_state.messages): | |
| if message["role"] == "user": | |
| st.markdown(f""" | |
| <div class="chat-message user-message"> | |
| <b>Vous:</b> {message["content"]} | |
| </div> | |
| """, unsafe_allow_html=True) | |
| else: | |
| st.markdown(f""" | |
| <div class="chat-message bot-message"> | |
| <b>Assistant:</b> {message["content"]} | |
| </div> | |
| """, unsafe_allow_html=True) | |
| if __name__ == "__main__": | |
| main() |