Skip to content

Commit

Permalink
add to .env.example reverb
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Apr 22, 2024
1 parent 0f59316 commit 0ac4c59
Show file tree
Hide file tree
Showing 16 changed files with 503 additions and 256 deletions.
17 changes: 15 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null

BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database

Expand Down Expand Up @@ -69,6 +68,20 @@ OPENAI_ORGANIZATION=
ADMIN_PASSWORD=password
ADMIN_EMAIL=[email protected]



REVERB_HOST="localhost"
REVERB_PORT=8080
REVERB_SCHEME=http

BROADCAST_CONNECTION=reverb


REVERB_APP_ID=SOMETHING
REVERB_APP_KEY=SOMETHING
REVERB_APP_SECRET=SOMETHING
REVERB_APP_SECRET=SOMETHING

VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
VITE_REVERB_PORT="${REVERB_PORT}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ yarn-error.log
/.idea
/.vscode
docs/images/.DS_Store
.DS_Store
37 changes: 37 additions & 0 deletions app/Console/Commands/TestConvertFileCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Console\Commands;

use Facades\App\Domains\Documents\Transformers\ProcessPpt;
use Illuminate\Console\Command;

class TestConvertFileCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:test-convert-file-command {full_path}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Give the path to the file to see if we can do it or not';

/**
* Execute the console command.
*/
public function handle()
{
$path = $this->argument('full_path');
$results = ProcessPpt::handle($path);

while ($results->valid()) {
$this->info($results->current());
$results->next();
}
}
}
68 changes: 68 additions & 0 deletions app/Domains/Documents/Transformers/ProcessPpt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace App\Domains\Documents\Transformers;

use Faker\Core\File;
use Generator;
use Illuminate\Support\Facades\File as FacadesFile;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\Drawing\Gd;
use PhpOffice\PhpPresentation\Shape\RichText;
use PhpOffice\PhpPresentation\Shape\Table;

class ProcessPpt
{
public function handle(string $pathToFile): Generator
{
$parser = IOFactory::createReader('PowerPoint2007');
if (! $parser->canRead($pathToFile)) {
throw new \Exception('Can not read the document '.$pathToFile);
}

$phppres = new PhpPresentation();
$oPHPPresentation = $parser->load($pathToFile);

foreach ($oPHPPresentation->getAllSlides() as $page_number => $page) {
try {
foreach ($page->getShapeCollection() as $shape) {
// Check if shape contains text
Log::info('Processing PPTX Document', [
'page_number' => $page_number,
'shape' => class_basename($shape),
]);
if ($shape instanceof RichText) {
// Get the text from the shapes
$page_number = $page_number + 1;
$pageContent = $shape->getPlainText();
$guid = $pathToFile.'_'.$page_number;

yield $pageContent;
} elseif($shape instanceof Table) {
$table = $shape->getRows();
foreach ($table as $row) {
foreach ($row->getCells() as $cell) {
$pageContent = $cell->getPlainText();
yield $pageContent;
}
}
} elseif($shape instanceof Gd) {
$mimtype = str($shape->getMimeType())->afterLast("/")->toString();
$contents = $shape->getContents();
$name = Str::random(10);
$nameAndType = $name . '.' . $mimtype;
$path = storage_path('app/temp/' . $nameAndType);
FacadesFile::put($path, $contents);
}
}
} catch (\Exception $e) {
Log::error('Error processing PPTX Document', [
'page_number' => $page_number,
'error' => $e->getMessage(),
]);
}
}
}
}
1 change: 1 addition & 0 deletions app/Http/Resources/DocumentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function toArray(Request $request): array
'id' => $this->id,
'file_path' => $this->file_path,
'summary' => $this->summary,
'summary_markdown' => str($this->summary)->markdown(),
'type' => str($this->type->name)->title()->toString(),
'status' => str($this->status->name)->headline()->toString(),
'document_chunks_count' => $this->document_chunks()->count(),
Expand Down
3 changes: 3 additions & 0 deletions app/Jobs/ProcessFileJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Log;
use Laravel\Pennant\Feature;
use LlmLaraHub\LlmDriver\LlmDriverFacade;
use PhpOffice\PhpPresentation\IOFactory;
Expand All @@ -37,6 +38,7 @@ public function handle(): void

if ($document->type === TypesEnum::Pptx) {
if (Feature::active('process-ppxt')) {
Log::info('Processing PPTX Document');
/**
* @NOTE
* Seems to work with my example
Expand Down Expand Up @@ -75,6 +77,7 @@ public function handle(): void
}

} elseif ($document->type === TypesEnum::PDF) {
Log::info('Processing PDF Document');
$batch = Bus::batch([
new ParsePdfFileJob($this->document),
])
Expand Down
1 change: 1 addition & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ public function boot(): void
return config('llmdriver.drivers.ollama.feature_flags.functions'); //just not ready yet
});


}
}
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"nwidart/laravel-modules": "^11.0",
"openai-php/laravel": "^0.8.1",
"owenvoke/blade-fontawesome": "^2.3",
"phpoffice/phppresentation": "^1.0",
"phpoffice/phppresentation": "dev-fix-pptx",
"smalot/pdfparser": "^2.9",
"spatie/laravel-data": "^4.4",
"spatie/laravel-markdown": "^2.3",
Expand Down Expand Up @@ -78,6 +78,12 @@
"test": "php artisan test",
"stan": "vendor/bin/phpstan analyse --memory-limit 2G"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/alnutile/php-presentation-fix"
}
],
"extra": {
"branch-alias": {
"dev-master": "11.x-dev"
Expand Down
Loading

0 comments on commit 0ac4c59

Please sign in to comment.