Spaces:
Sleeping
Sleeping
Download server/services/testHuggingFaceAPI.js from lemachinarbo/lucas-dev: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/spaces/lemachinarbo/lucas-dev/resolve/main/server/services/testHuggingFaceAPI.js
- Command line
-
hf download hf://spaces/lemachinarbo/lucas-dev/server/services/testHuggingFaceAPI.js
-
curl -L -o testHuggingFaceAPI.js https://huggingface.co/spaces/lemachinarbo/lucas-dev/resolve/main/server/services/testHuggingFaceAPI.js
1.06 kB
| import axios from "axios"; | |
| import dotenv from "dotenv"; | |
| // Load environment variables | |
| dotenv.config(); | |
| console.log(process.env.HUGGING_FACE_API_KEY); // Verify if the key loads correctly | |
| const testHuggingFaceAPI = async () => { | |
| try { | |
| // Input text for emotion analysis | |
| const inputText = "I love using Hugging Face's APIs!"; | |
| // API endpoint for Hugging Face Inference (GoEmotions model) | |
| const apiUrl = | |
| "https://api-inference.huggingface.co/models/bhadresh-savani/bert-base-go-emotion"; | |
| // Make the API request | |
| const response = await axios.post( | |
| apiUrl, | |
| { inputs: inputText }, | |
| { | |
| headers: { | |
| Authorization: `Bearer ${process.env.HUGGING_FACE_API_KEY}`, | |
| "Content-Type": "application/json", | |
| }, | |
| } | |
| ); | |
| // Log the response from the API | |
| console.log("Hugging Face API Response:", response.data); | |
| } catch (error) { | |
| console.error( | |
| "Error testing Hugging Face API:", | |
| error.response?.data || error.message | |
| ); | |
| } | |
| }; | |
| testHuggingFaceAPI(); | |