Spaces:
Build error
Build error
Download test.py from Soguy/test: direct link, hf CLI and curl.
- Browser
- Download file 718 Bytes
-
https://huggingface.co/spaces/Soguy/test/resolve/main/test.py
- Command line
-
hf download hf://spaces/Soguy/test/test.py
-
curl -L -o test.py https://huggingface.co/spaces/Soguy/test/resolve/main/test.py
718 Bytes
| import requests | |
| import os | |
| from dotenv import load_dotenv | |
| # Charger les variables d'environnement depuis .env | |
| load_dotenv() | |
| # Récupérer la clé API Hugging Face depuis .env | |
| HF_API_TOKEN = os.getenv("HF_API_TOKEN") | |
| # URL de l'API d'inférence | |
| API_URL = "https://api-inference.huggingface.co/models/meta-llama/Meta-Llama-3-8B" | |
| headers = {"Authorization": f"Bearer {HF_API_TOKEN}"} | |
| # Fonction pour envoyer une requête | |
| def query(payload): | |
| response = requests.post(API_URL, headers=headers, json=payload) | |
| return response.json() | |
| # Test du modèle avec un exemple simple | |
| output = query({ | |
| "inputs": "What are the benefits of artificial intelligence in education?", | |
| }) | |
| # Afficher le résultat | |
| print(output) | |