FIX_CHATBOT_BG_IMG_CHNAGE

This commit is contained in:
velz 2025-08-16 17:35:18 +05:30
parent d39b2ca2d3
commit ae6b16a759
4 changed files with 309 additions and 15 deletions

View File

@ -47,6 +47,7 @@ $routes->get("frontend_content", "AppContentManagementController::frontend_conte
// $routes->get('/', 'LoginController::index');
$routes->get('/test', 'Home::index');
$routes->get('/check_gemini', 'Home::check_Gemini');
$routes->get('/check_gemini2', 'Home::check_gemini_2');
$routes->get('/login', 'LoginController::index'); ///auth/google
$routes->get('/loginPos', 'LoginController::loginPos'); //login POS team
$routes->post('/getVerifyPosMobileNo', 'LoginController::getVerifyPosMobileNo'); //Verify POS team mobile no

View File

@ -7,6 +7,10 @@ use GeminiAPI\Client;
use GeminiAPI\Resources\ModelName;
use GeminiAPI\Resources\Parts\TextPart;
use Mpdf\Mpdf;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Shared\Date;
class Home extends PublicController
{
@ -36,24 +40,300 @@ class Home extends PublicController
public function check_Gemini()
{
try {
$apiKey = 'AIzaSyBbx-uotRBqkYhqLpmD60420E_a0G0duP8';
// Initialize the Gemini client
$client = new Client($apiKey);
try {
$apiKey = 'AIzaSyBbx-uotRBqkYhqLpmD60420E_a0G0duP8';
// Initialize the Gemini client
$client = new Client($apiKey);
// Send a prompt to the Gemini Pro model
$response = $client->generativeModel(ModelName::GEMINI_PRO)->generateContent(
new TextPart('Write a short, creative story about a knight and a dragon.')
);
// Send a prompt to the Gemini Pro model
$response = $client->generativeModel(ModelName::GEMINI_PRO)->generateContent(
new TextPart('Write a short, creative story about a knight and a dragon.')
);
// Display the generated text
$data['gemini_response'] = $response->text();
} catch (\Exception $e) {
// Handle any errors that occur during the API call
$data['gemini_response'] = 'An error occurred: ' . $e->getMessage();
}
// Display the generated text
$data['gemini_response'] = $response->text();
} catch (\Exception $e) {
// Handle any errors that occur during the API call
$data['gemini_response'] = 'An error occurred: ' . $e->getMessage();
}
print_rr($data);
}
public function check_gemini_2()
{
// $this->convertToPdf();die();
// Replace with your actual Gemini API key
$apiKey = 'AIzaSyBbx-uotRBqkYhqLpmD60420E_a0G0duP8';
// The model to use and the API endpoint
$model = "gemini-pro";
$model = "gemini-2.5-flash";
// $model = "gemini-1.5-pro";
// $model = "gemini-1.5-pro";
$url = "https://generativelanguage.googleapis.com/v1beta/models/{$model}:generateContent?key={$apiKey}";
$filePath = 'C:\Users\Venba\Downloads\NIA MDU May-2025 (2).pdf';
$filePath = 'C:/Users/Venba/Desktop/ins stmts/NIC MDU June-2025 (1).pdf';
$filePath = 'C:/Users/Venba/Desktop/ins stmts/UIIC GR June-2025.pdf';
$filePath = 'C:/Users/Venba/Desktop/ins stmts/UIIC VLR June-2025 (2).xlsx';
$filePath = 'C:/Users/Venba/Desktop/ins stmts/pdf/2.pdf';
$filePath = 'C:\Users\Venba\Downloads\Raheja June-2025.csv';
// $filePath = 'C:/Users/Venba/Downloads/Raheja June-2025.pdf';
// $filePath = 'C:/Users/Venba/Desktop/ins stmts/ICICI Pru June-2025 (1).xlsx';
// $filePath = 'C:/Users/Venba/Desktop/ins stmts/Digit Life June-2025.xlsx';
// Check if the file exists
if (!file_exists($filePath)) {
die("Error: File not found at {$filePath}");
}
// Get the file's MIME type using the finfo extension
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mimeType = finfo_file($finfo, $filePath);
finfo_close($finfo);
// print_r($mimeType);die();
// Define supported inline MIME types
$supportedInlineMimeTypes = ['application/pdf','text/csv'];
// Read the file content and encode it to Base64
$fileContent = file_get_contents($filePath);
$base64Content = base64_encode($fileContent);
// The prompt you want to send to the model
$prompt = "give me a json with emp data like name,age,dob,mobile and email. only json not any explanations";
$prompt = "Read the following insurer monthly statement file and convert into JSON format as sample specified.attach statement items in 'items' key and if any other data available put it in 'meta'. Give me only JSON,not any explanations. If you find the same details like insured name, policy number,endorsement no,policy start date,policy end date group it as single policy and identify base premium, third party premium and terrorism premium.";
$prompt .= "{\'items\': [{\'sno\': 1, \'policy_no\': \'\', \'insured_name\': \'\', \'endorsement_no\': \'\', \'policy_start_date\': \'\', \'policy_end_date\': \'\', \'actual_base_premium_amount\': \'\', \'actual_third_party_premium_amount\': \'\', \'actual_terrorism_premium_amount\': \'\', \'actual_base_premium_percentage\': \'\', \'actual_third_party_premium_percentage\': \'\', \'actual_terrorism_premium_percentage\': \'\', \'actual_bp_brokerage_amount\': \'\', \'actual_tp_brokerage_amount\': \'\', \'actual_tep_brokerage_amount\': \'\', \'reward_amount\': \'\'}]}";
$payloadPart = null;
// The text part of the prompt
$text_part = [
"text" => $prompt
];
// Conditionally handle the file upload based on MIME type
if (in_array($mimeType, $supportedInlineMimeTypes)) {
echo "Detected supported format inline MIME type ({$mimeType})";
// Handle PDF as inline data
$fileContent = file_get_contents($filePath);
$base64Content = base64_encode($fileContent);
$payloadPart = [
"inlineData" => [
"mimeType" => $mimeType,
"data" => $base64Content
]
];
$content_parts = [
"parts" => [
$text_part,
$payloadPart
]
];
} else {
// Handle Excel/CSV using the Files API
echo "Detected unsupported inline MIME type ({$mimeType}). Uploading via Files API...\n";
$fileInfo = $this->uploadFileToGemini($filePath, $apiKey); // Pass apiKey
print_r($fileInfo);
// The file part, using the URI from the Files API upload
$file_part = [
"fileData" => [
"fileUri" => $fileInfo['uri'],
"mimeType" => $fileInfo['mimeType']
]
];
// The full content array, containing both parts
$content_parts = [
"parts" => [
$text_part,
$file_part
]
];
}
// The final JSON payload
$data = [
"contents" => [
$content_parts
]
];
// Encode the data to a JSON string
$json_data = json_encode($data);
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); // Set the Content-Type header
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); // Set the JSON payload
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response as a string
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Optional: to bypass SSL verification if needed (not recommended for production)
// Execute the cURL request and get the response
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
echo 'cURL Error: ' . curl_error($ch);
}
// Close the cURL handle
curl_close($ch);
// Decode the JSON response
$responseData = json_decode($response, true);
echo '<pre>';
print_r($responseData);
echo '<pre>';
// Check if the response contains generated text
if (isset($responseData['candidates'][0]['content']['parts'][0]['text'])) {
$generatedText = $responseData['candidates'][0]['content']['parts'][0]['text'];
echo "Generated Text: " . $generatedText;
} else {
echo "Error or no text generated. Response: " . $response;
}
print_rr($data);
}
// Function to upload a file to the Gemini Files API
function uploadFileToGemini($filePath, $apiKey)
{
// Define the URL for the Files API upload
$uploadUrl = "https://generativelanguage.googleapis.com/upload/v1beta/files?key={$apiKey}";
// Get file info
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$fileMimeType = finfo_file($finfo, $filePath);
finfo_close($finfo);
$displayName = basename($filePath);
// Build the request body for the Files API
$fileUploadData = [
'file' => [
'display_name' => $displayName,
],
];
$jsonUploadData = json_encode($fileUploadData);
// Initialize cURL for the upload
$ch_upload = curl_init();
curl_setopt($ch_upload, CURLOPT_URL, $uploadUrl);
curl_setopt($ch_upload, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch_upload, CURLOPT_POST, true);
// Use CURLFile for multipart/form-data upload
$payload = [
'metadata' => $jsonUploadData,
'file' => new \CURLFile($filePath, $fileMimeType, $displayName),
];
curl_setopt($ch_upload, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch_upload, CURLOPT_HTTPHEADER, [
'X-Goog-Upload-Protocol: multipart',
]);
curl_setopt($ch_upload, CURLOPT_SSL_VERIFYPEER, false); // Optional: not for production
// Execute the upload request
$uploadResponse = curl_exec($ch_upload);
if (curl_errno($ch_upload)) {
die('cURL Error (Files API): ' . curl_error($ch_upload));
}
curl_close($ch_upload);
$uploadResponseData = json_decode($uploadResponse, true);
// Check for a successful upload and return the file URI
if (!isset($uploadResponseData['file']['uri'])) {
die("Error uploading file. Response: " . $uploadResponse);
}
return [
'uri' => $uploadResponseData['file']['uri'],
'mimeType' => $fileMimeType
];
}
public function convertToPdf($inputFile = null)
{
// 1. Load your Excel file
$inputFile = 'C:/Users/Venba/Desktop/ins stmts/Raheja June-2025.xlsx';
// $inputFile = 'C:/Users/Venba/Desktop/ins stmts/pdf/sample.pdf';
$spreadsheet = IOFactory::load($inputFile);
// 2. Initialize mPDF with proper configuration
$mpdf = new Mpdf([
'mode' => 'utf-8',
'format' => 'A4',
'margin_header' => 5,
'margin_footer' => 5,
'orientation' => 'L',
'default_font_size' => 18,
// 'default_font' => 'Arial'
]);
// 3. Process each worksheet
foreach ($spreadsheet->getWorksheetIterator() as $worksheet) {
// Get HTML representation of the sheet
$html = $this->worksheetToHtml($worksheet);
// print_r($html);
// Add to PDF
$mpdf->AddPage();
$mpdf->WriteHTML($html);
}
$pdfPath = 'C:/Users/Venba/Desktop/ins stmts/pdf/2.pdf';
// $pdfPath = WRITEPATH.'tmp';
$mpdf->Output($pdfPath, \Mpdf\Output\Destination::FILE); // Save file on server
// 4. Output
// $mpdf->Output('financial_report.pdf', 'D');
}
protected function worksheetToHtml($worksheet)
{
// Customize this based on your needs
$html = '<h2>' . htmlspecialchars($worksheet->getTitle()) . '</h2>';
$html .= '<table border="1" cellpadding="5">';
foreach ($worksheet->getRowIterator() as $row) {
$html .= '<tr>';
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true);
foreach ($cellIterator as $cell) {
$value = $cell->getValue();
// ✅ Detect and format Excel date cells
if (Date::isDateTime($cell)) {
$formattedValue = Date::excelToDateTimeObject($value)->format('Y-m-d');
} else {
$formattedValue = $cell->getCalculatedValue();
}
$html .= '<td>' . htmlspecialchars($formattedValue) . '</td>';
}
$html .= '</tr>';
}
$html .= '</table>';
return $html;
}
}

View File

@ -203,6 +203,14 @@ function setupMessageObserver() {
return;
}
// ✅ Change iframe body background here
doc.body.style.background = "url('https://venbait.in/nhance/app/dev/assets/chat-bg.jpg') no-repeat center center fixed";
// doc.body.style.background = "covercover";
doc.body.style.backgroundSize = "cover";
doc.body.style.margin = "0"; // optional
// Wait for the document to be ready
const waitForElement = () => {
const messageArea = doc.querySelector("#messageArea");
@ -351,6 +359,10 @@ function setupMessageObserver() {
height: 100% !important;
width: 100% !important;
}
iframe#body {
background: none !important;
}
`;
document.getElementsByTagName('head')[0].appendChild(style);
}

View File

@ -21,6 +21,7 @@
"google/apiclient": "^2.15.0",
"kreait/firebase-php": "^7.0",
"laminas/laminas-escaper": "^2.9",
"mpdf/mpdf": "*",
"php-amqplib/php-amqplib": "^2.8",
"phpmailer/phpmailer": "^6.9",
"phpoffice/phpspreadsheet": "^2.1",