Download app.py from enoderr/Bot: direct link, hf CLI and curl.
- Browser
- Download file 893 Bytes
-
https://huggingface.co/spaces/enoderr/Bot/resolve/main/app.py
- Command line
-
hf download hf://spaces/enoderr/Bot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/enoderr/Bot/resolve/main/app.py
893 Bytes
| import streamlit as st | |
| from transformers import pipeline | |
| # Titre de l'application | |
| st.title("Générateur de Texte avec Hugging Face") | |
| # Sélection du modèle | |
| model_name = st.selectbox("Choisissez un modèle :", ["gpt2", "distilgpt2"]) | |
| # Chargement du pipeline de génération de texte | |
| text_generator = pipeline("text-generation", model=model_name) | |
| # Entrée utilisateur | |
| prompt = st.text_area("Entrez votre prompt :", "Écrivez ici...") | |
| # Bouton pour générer le texte | |
| if st.button("Générer"): | |
| if prompt: | |
| with st.spinner("Génération en cours..."): | |
| generated_text = text_generator(prompt, max_length=50, num_return_sequences=1)[0]['generated_text'] | |
| st.success("Texte généré :") | |
| st.write(generated_text) | |
| else: | |
| st.error("Veuillez entrer un prompt.") | |
| # Lancer l'application Streamlit | |
| if __name__ == "__main__": | |
| st.run() | |