use Swapinvidya\HuggingFaceClient\HuggingFaceClient;
public function generateText(HuggingFaceClient $huggingFaceClient)
{
$response = $huggingFaceClient->generateText('gpt2', 'Write a short story about a hero.');
return response()->json($response);
}
public function generateImage(HuggingFaceClient $huggingFaceClient)
{
$response = $huggingFaceClient->generateImage('stable-diffusion-v1', 'A futuristic city with flying cars.');
return response()->json($response);
}
public function generateCompletion(HuggingFaceClient $huggingFaceClient)
{
$params = [
'inputs' => 'Explain the theory of relativity in simple terms.',
'parameters' => [
'temperature' => 0.7,
'max_new_tokens' => 200,
],
];
$response = $huggingFaceClient->generateCompletion('gpt-neo', $params);
return response()->json($response);
}
$response = $huggingFaceClient->generateText('gpt2', 'Hello world');
if (isset($response['error'])) {
// Handle the error
return response()->json(['error' => $response['error']], 500);
}
return response()->json($response);