From 991acb14d9902748a126940506a0d8049e9d535a Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sun, 26 Oct 2025 18:38:54 +0000 Subject: [PATCH] MAKDOC3 --- api/generate_report.php | 327 ++++++++++++++++++++++++++++++++++++++++ index.php | 48 +++++- 2 files changed, 371 insertions(+), 4 deletions(-) create mode 100644 api/generate_report.php diff --git a/api/generate_report.php b/api/generate_report.php new file mode 100644 index 0000000..41cd922 --- /dev/null +++ b/api/generate_report.php @@ -0,0 +1,327 @@ +AI-Generated Summary Report"; + $report .= "

A high-level overview of the key points in the document.


"; + + $sentences = preg_split('/(?<=[.?!])\s+/', $text, -1, PREG_SPLIT_NO_EMPTY); + $num_sentences = count($sentences); + $summary_sentences = []; + $sentences_to_take = 3; + + if ($num_sentences <= ($sentences_to_take * 2)) { + $summary_sentences = $sentences; + } else { + $summary_sentences = array_slice($sentences, 0, $sentences_to_take); + $summary_sentences[] = "[...]"; + $summary_sentences = array_merge($summary_sentences, array_slice($sentences, -$sentences_to_take)); + } + + $report .= "

Key Points:

"; + return $report; +} + +/** + * Extracts sentences that appear to reference dates or events to create a timeline. + */ +function generate_timeline_report($text) { + $report = "

AI-Generated Timeline of Events

"; + $report .= "

A chronological list of events and important dates mentioned in the document.


"; + + // Regex to find sentences with dates (e.g., 25/12/2023, Dec 25, 2023) or time-related keywords. + $date_pattern = '/\b(\d{1,2}[-\/]\d{1,2}[-\/]\d{2,4}|\w+\s\d{1,2},\s\d{4})\b/i'; + $keyword_pattern = '/\b(on|at|before|after|during|later|yesterday|today|tomorrow|meanwhile)\b/i'; + + $sentences = preg_split('/(?<=[.?!])\s+/', $text, -1, PREG_SPLIT_NO_EMPTY); + $timeline_events = []; + + foreach ($sentences as $sentence) { + if (preg_match($date_pattern, $sentence) || preg_match($keyword_pattern, $sentence)) { + $timeline_events[] = $sentence; + } + } + + $report .= "

Potential Events:

"; + if (empty($timeline_events)) { + $report .= "

No specific date or time-based events were detected by the AI.

"; + } else { + $report .= ""; + } + return $report; +} + +/** + * Extracts names of individuals based on common titles. + */ +function generate_persons_report($text) { + $report = "

AI-Generated List of Key Individuals

"; + $report .= "

A list of individuals who may be relevant to the document.


"; + + // Regex to find names with titles (Mr., Mrs., Dr., etc.) or potential full names. + $pattern = '/\b(Mr\.|Mrs\.|Ms\.|Dr\.|Prof\.)\s+[A-Z][a-z]+(\s+[A-Z][a-z]+)?/i'; + preg_match_all($pattern, $text, $matches); + + $persons = array_unique($matches[0]); + + $report .= "

Mentioned Individuals:

"; + if (empty($persons)) { + $report .= "

No individuals with titles (e.g., Mr., Dr.) were automatically detected.

"; + } else { + $report .= ""; + } + return $report; +} + +/** + * Extracts a log of potential evidence markers. + */ +function generate_evidence_report($text) { + $report = "

AI-Generated Evidence Log

"; + $report .= "

A log of items marked as potential evidence or exhibits.


"; + + // Regex to find evidence-related keywords. + $pattern = '/\b(Exhibit|Appendix|Figure|Table|Attachment|Document|Photo|Video|Audio)\s+[A-Z0-9\-]+/i'; + preg_match_all($pattern, $text, $matches); + + $evidence_items = array_unique($matches[0]); + + $report .= "

Potential Evidence:

"; + if (empty($evidence_items)) { + $report .= "

No items matching standard evidence markers (e.g., 'Exhibit A', 'Document 123') were found.

"; + } else { + $report .= ""; + } + return $report; +} + +/** + * Generates a placeholder for a Case Diary Status Report. + */ +function generate_case_diary_report($text) { + $report = "

Case Diary Status Report

"; + $report .= "

This is a placeholder for the Case Diary Status Report. Future development will populate this with relevant case diary entries from the text.


"; + $report .= "

Extracted Text:

" . htmlspecialchars(substr($text, 0, 500)) . "...

"; + return $report; +} + +/** + * Generates a placeholder for a Bail Reply. + */ +function generate_bail_reply_report($text) { + $report = "

Bail Reply

"; + $report .= "

This is a placeholder for the Bail Reply. Future development will populate this with arguments and evidence against bail from the text.


"; + $report .= "

Extracted Text:

" . htmlspecialchars(substr($text, 0, 500)) . "...

"; + return $report; +} + +/** + * Generates a placeholder for a High Court Status Report. + */ +function generate_high_court_status_report($text) { + $report = "

High Court Status Report

"; + $report .= "

This is a placeholder for the High Court Status Report. Future development will populate this with case status details for the High Court.


"; + $report .= "

Extracted Text:

" . htmlspecialchars(substr($text, 0, 500)) . "...

"; + return $report; +} + +/** + * Generates a placeholder for a Seizure Memo. + */ +function generate_seizure_memo_report($text) { + $report = "

Seizure Memo

"; + $report .= "

This is a placeholder for the Seizure Memo. Future development will populate this with details of seized items from the text.


"; + $report .= "

Extracted Text:

" . htmlspecialchars(substr($text, 0, 500)) . "...

"; + return $report; +} + +/** + * Generates a placeholder for a Chargesheet. + */ +function generate_chargesheet_report($text) { + $report = "

Chargesheet

"; + $report .= "

This is a placeholder for the Chargesheet. Future development will populate this with charges, evidence, and witness lists from the text.


"; + $report .= "

Extracted Text:

" . htmlspecialchars(substr($text, 0, 500)) . "...

"; + return $report; +} + +/** + * Generates a placeholder for a Disclosure Statement. + */ +function generate_disclosure_statement_report($text) { + $report = "

Disclosure Statement

"; + $report .= "

This is a placeholder for the Disclosure Statement. Future development will populate this with disclosed information from the text.


"; + $report .= "

Extracted Text:

" . htmlspecialchars(substr($text, 0, 500)) . "...

"; + return $report; +} + +/** + * Generates a placeholder for an Exemption Request. + */ +function generate_exemption_request_report($text) { + $report = "

Exemption Request

"; + $report .= "

This is a placeholder for the Exemption Request. Future development will populate this with reasons and justifications for exemption from the text.


"; + $report .= "

Extracted Text:

" . htmlspecialchars(substr($text, 0, 500)) . "...

"; + return $report; +} + +/** + * Generates a placeholder for an NBW (Non-Bailable Warrant). + */ +function generate_nbw_report($text) { + $report = "

NBW (Non-Bailable Warrant)

"; + $report .= "

This is a placeholder for the NBW. Future development will populate this with details for the warrant application from the text.


"; + $report .= "

Extracted Text:

" . htmlspecialchars(substr($text, 0, 500)) . "...

"; + return $report; +} + +/** + * Generates a report for a Reply for Release of RC. + */ +function generate_release_of_rc_reply_report($text) { + $report = "

Reply for Release of RC

"; + + // Extract details using regex + preg_match('/IN THE HON’BLE COURT OF (.*)/', $text, $court); + preg_match('/FIR NO.: (.*)/', $text, $fir_no); + preg_match('/U\/S: (.*)/', $text, $us); + preg_match('/P.S.: (.*)/', $text, $ps); + preg_match('/State. vs. (.*)/', $text, $parties); + preg_match('/motorcycle bearing no. (.*?),/', $text, $vehicle_no); + preg_match('/applicant, (.*?)\./', $text, $applicant); + preg_match('/accused, (.*?)[,.]/', $text, $accused); + preg_match('/disposed of by this Hon'ble Court on (.*)\./', $text, $disposal_date); + + $report .= "

IN THE HON’BLE COURT OF " . htmlspecialchars($court[1] ?? '...') . "

"; + $report .= "

FIR NO.: " . htmlspecialchars($fir_no[1] ?? '...') . "

"; + $report .= "

U/S: " . htmlspecialchars($us[1] ?? '...') . "

"; + $report .= "

P.S.: " . htmlspecialchars($ps[1] ?? '...') . "

"; + $report .= "

In the matter of: State. vs. " . htmlspecialchars($parties[1] ?? '...') . "

"; + $report .= "
"; + $report .= "

Subject- Reply for Release of RC

"; + $report .= "

HON’BLE SIR,

"; + $report .= "

Most respectfully submitted that present application for the release of the registration certificate (RC) of motorcycle bearing no. " . htmlspecialchars($vehicle_no[1] ?? '...') . ", filed by the applicant, " . htmlspecialchars($applicant[1] ?? '...') . ".

"; + $report .= "

The applicant stood as surety for the accused, " . htmlspecialchars($accused[1] ?? '...') . ", during the pendency of the case.

"; + $report .= "

The case has been disposed of by this Hon'ble Court on " . htmlspecialchars($disposal_date[1] ?? '...') . ".

"; + $report .= "

That no other appeal in this regard is pending in any other Hon’ble Court or High Court.

"; + $report .= "

That undersigned have no objection on release of RC.

"; + $report .= "

Submitted Please.

"; + + return $report; +} + +/** + * Generates a report for a Request for Cartridges. + */ +function generate_request_for_cartridges_report($text) { + $report = "

Request for Cartridges

"; + + // Extract details using regex + preg_match('/FIR NO . (.*)/', $text, $fir_no); + preg_match('/PS (.*) DELHI/', $text, $ps); + preg_match('/TO (.*)/', $text, $to); + preg_match('/provide (.*) for test firing/', $text, $cartridges); + preg_match('/sent to (.*) Vide/', $text, $fsl); + preg_match('/Letter No. (.*) Dated/', $text, $letter_no); + preg_match('/Dated (.*) for expert/', $text, $letter_date); + + + $report .= "

FIR NO.: " . htmlspecialchars($fir_no[1] ?? '...') . "

"; + $report .= "

P.S.: " . htmlspecialchars($ps[1] ?? '...') . "

"; + $report .= "

TO: " . htmlspecialchars($to[1] ?? '...') . "

"; + $report .= "
"; + $report .= "

Subject- Request to provide " . htmlspecialchars($cartridges[1] ?? '...') . " for test firing

"; + $report .= "

Sir,

"; + $report .= "

Most respectfully submitted that recovered arms and ammunition were sent to " . htmlspecialchars($fsl[1] ?? '...') . " Vide Letter No. " . htmlspecialchars($letter_no[1] ?? '...') . " Dated " . htmlspecialchars($letter_date[1] ?? '...') . " for expert opinion.

"; + $report .= "

That FSL raised objection and asked to provide " . htmlspecialchars($cartridges[1] ?? '...') . " for Test firing.

"; + $report .= "

Therefore it is requested that for further proceedings " . htmlspecialchars($cartridges[1] ?? '...') . " may kindly be provided.

"; + $report .= "

Submitted please.

"; + + return $report; +} + + +// --- Main Logic --- + +$data = json_decode(file_get_contents('php://input'), true); +$text = $data['text'] ?? ''; +$template = $data['template'] ?? 'summary'; // Default to 'summary' + +if (empty($text)) { + echo json_encode(['report' => 'No text provided to generate a report.']); + exit; +} + +$final_report = ''; + +switch ($template) { + case 'timeline': + $final_report = generate_timeline_report($text); + break; + case 'persons': + $final_report = generate_persons_report($text); + break; + case 'evidence': + $final_report = generate_evidence_report($text); + break; + case 'case_diary': + $final_report = generate_case_diary_report($text); + break; + case 'bail_reply': + $final_report = generate_bail_reply_report($text); + break; + case 'high_court_status': + $final_report = generate_high_court_status_report($text); + break; + case 'seizure_memo': + $final_report = generate_seizure_memo_report($text); + break; + case 'chargesheet': + $final_report = generate_chargesheet_report($text); + break; + case 'disclosure_statement': + $final_report = generate_disclosure_statement_report($text); + break; + case 'exemption_request': + $final_report = generate_exemption_request_report($text); + break; + case 'nbw': + $final_report = generate_nbw_report($text); + break; + case 'release_of_rc_reply': + $final_report = generate_release_of_rc_reply_report($text); + break; + case 'request_for_cartridges': + $final_report = generate_request_for_cartridges_report($text); + break; + case 'summary': + default: + $final_report = generate_summary_report($text); + break; +} + +$final_report .= "

--- End of Report ---

"; + +// Return the report as JSON +echo json_encode(['report' => $final_report]); \ No newline at end of file diff --git a/index.php b/index.php index 88c2f9e..83c5039 100644 --- a/index.php +++ b/index.php @@ -28,6 +28,7 @@ const [fileContent, setFileContent] = useState(''); const [isLoading, setIsLoading] = useState(false); const [reportContent, setReportContent] = useState('AI-generated report will appear here.'); + const [reportTemplate, setReportTemplate] = useState('summary'); const handleFileChange = (e) => { const selectedFile = e.target.files[0]; @@ -85,8 +86,22 @@ }; const generateReport = () => { - // Placeholder for AI report generation - setReportContent("Generating report... (This is a placeholder, AI integration is not yet implemented). Based on the document, the key points are..."); + setReportContent('
'); + fetch('/api/generate_report.php', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ text: fileContent, template: reportTemplate }), + }) + .then(response => response.json()) + .then(data => { + setReportContent(data.report); + }) + .catch(error => { + console.error('Error generating report:', error); + setReportContent('An error occurred while generating the report.'); + }); }; const exportToPdf = () => { @@ -165,13 +180,38 @@

Generated Report

-

{reportContent}

+
{/* Action Buttons */} -
+
+
+ +
+ +
+