Spaces:
Runtime error
Runtime error
File size: 1,055 Bytes
90b3952 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 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();
|