Spaces:
Runtime error
Runtime error
Download app.py from charlesbg/charlesspace: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/charlesbg/charlesspace/resolve/main/app.py
- Command line
-
hf download hf://spaces/charlesbg/charlesspace/app.py
-
curl -L -o app.py https://huggingface.co/spaces/charlesbg/charlesspace/resolve/main/app.py
1.45 kB
| import gradio as gr | |
| from transformers import pipeline | |
| # Chargement du modèle | |
| ia = pipeline("text2text-generation", model="google/flan-t5-base") | |
| # Fonction qui génère la réponse | |
| def repondre(question, matiere): | |
| if not question.strip(): | |
| return "Écris une question pour que je puisse t'aider ! 😄" | |
| prompt = f"Tu es un professeur de {matiere.lower()}. Explique simplement : {question}" | |
| resultat = ia(prompt, max_length=150, do_sample=False)[0]["generated_text"] | |
| return resultat.strip() | |
| # Interface Gradio | |
| interface = gr.Interface( | |
| fn=repondre, | |
| inputs=[ | |
| gr.Textbox(label="📝 Pose ta question ici :", placeholder="Ex : Pourquoi le ciel est bleu ?"), | |
| gr.Radio( | |
| ["Maths", "Français", "Histoire", "Anglais", "Sciences", "Géographie"], | |
| label="📚 Choisis ta matière" | |
| ) | |
| ], | |
| outputs=gr.Textbox(label="💡 Réponse de l'IA"), | |
| title="🎓 ProfBot – L’IA qui aide toute la classe", | |
| description="Pose une question dans la matière de ton choix et ProfBot t'explique simplement ✨", | |
| theme="default", | |
| examples=[ | |
| ["Comment additionner des fractions ?", "Maths"], | |
| ["Qu'est-ce qu'une métaphore ?", "Français"], | |
| ["Qui était Napoléon ?", "Histoire"], | |
| ["What is the past tense of 'go'?", "Anglais"], | |
| ["Pourquoi les volcans explosent ?", "Sciences"] | |
| ] | |
| ) | |
| # Lancer l'application Gradio | |
| interface.launch() | |