-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-proxy.php
More file actions
29 lines (24 loc) · 817 Bytes
/
api-proxy.php
File metadata and controls
29 lines (24 loc) · 817 Bytes
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
<?php
require_once 'secure/config.php'; // Adjust path as needed
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Allow-Headers: Content-Type');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$input = json_decode(file_get_contents('php://input'), true);
$prompt = $input['prompt'] ?? '';
if (empty($prompt)) {
http_response_code(400);
echo json_encode(['error' => 'No prompt provided']);
exit;
}
$response = callHuggingFace($prompt, HUGGING_FACE_API_KEY);
echo $response;
} else {
http_response_code(405);
echo json_encode(['error' => 'Method not allowed']);
}
function callHuggingFace($prompt, $apiKey) {
// ... same as previous implementation
}
?>