├── .editorconfig
├── .firebaserc
├── .gitignore
├── .vscode
├── extensions.json
├── launch.json
└── tasks.json
├── LICENSE
├── README.md
├── angular.json
├── atlas-app-services
├── functions
│ ├── Atlas_Triggers_analyzeReviewSentiment_1686394580.js
│ ├── Atlas_Triggers_summarizeReviewsSentiment_1686475894.js
│ └── config.json
└── triggers
│ ├── analyzeReviewSentiment.json
│ └── summarizeReviewsSentiment.json
├── firebase.json
├── google-cloud-functions
├── analyze-media
│ ├── index.js
│ └── package.json
├── analyze-sentiment
│ ├── index.js
│ └── package.json
├── create-signed-url
│ ├── index.js
│ └── package.json
└── summarize-review-sentiment
│ ├── main.py
│ └── requirements.txt
├── package-lock.json
├── package.json
├── src
├── app
│ ├── address.ts
│ ├── app-routing.module.ts
│ ├── app.component.html
│ ├── app.component.scss
│ ├── app.component.ts
│ ├── app.module.ts
│ ├── change-events.ts
│ ├── drag-and-drop.directive.ts
│ ├── file-handle.service.spec.ts
│ ├── file-handle.service.ts
│ ├── grade.ts
│ ├── helpers
│ │ └── objectId.ts
│ ├── image-detailed-dialog
│ │ ├── media-dialog.component.html
│ │ ├── media-dialog.component.scss
│ │ └── media-dialog.component.ts
│ ├── image-uplouder.service.ts
│ ├── media-preview
│ │ ├── media-preview.component.html
│ │ ├── media-preview.component.scss
│ │ └── media-preview.component.ts
│ ├── media-upload-dialog
│ │ ├── media-upload-dialog.component.html
│ │ ├── media-upload-dialog.component.scss
│ │ └── media-upload-dialog.component.ts
│ ├── navbar
│ │ ├── navbar.component.html
│ │ ├── navbar.component.scss
│ │ ├── navbar.component.spec.ts
│ │ └── navbar.component.ts
│ ├── realm-app.service.ts
│ ├── restaurant-details-guided
│ │ ├── restaurant-details-guided.component.html
│ │ ├── restaurant-details-guided.component.scss
│ │ └── restaurant-details-guided.component.ts
│ ├── restaurant-details
│ │ ├── restaurant-details.component.html
│ │ ├── restaurant-details.component.scss
│ │ └── restaurant-details.component.ts
│ ├── restaurant.service.ts
│ ├── restaurant.ts
│ ├── restaurants-list-guided
│ │ ├── restaurants-list-guided.component.html
│ │ ├── restaurants-list-guided.component.scss
│ │ └── restaurants-list-guided.component.ts
│ ├── restaurants-list
│ │ ├── restaurants-list.component.html
│ │ ├── restaurants-list.component.scss
│ │ └── restaurants-list.component.ts
│ ├── review-form
│ │ ├── review-form.component.html
│ │ ├── review-form.component.scss
│ │ └── review-form.component.ts
│ ├── review.service.ts
│ ├── review.ts
│ ├── rxjs-operators.ts
│ └── uploaded-media.ts
├── assets
│ └── .gitkeep
├── config.ts
├── favicon.ico
├── index.html
├── main.ts
└── styles.scss
├── tsconfig.app.json
├── tsconfig.json
└── tsconfig.spec.json
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see https://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.ts]
12 | quote_type = single
13 |
14 | [*.md]
15 | max_line_length = off
16 | trim_trailing_whitespace = false
17 |
--------------------------------------------------------------------------------
/.firebaserc:
--------------------------------------------------------------------------------
1 | {
2 | "targets": {
3 | "atlas-ai-demos": {
4 | "hosting": {
5 | "ai-restaurants": [
6 | "atlas-ai-demos"
7 | ]
8 | }
9 | }
10 | },
11 | "projects": {
12 | "default": "atlas-ai-demos"
13 | }
14 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # Compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 | /bazel-out
8 |
9 | # Node
10 | /node_modules
11 | npm-debug.log
12 | yarn-error.log
13 |
14 | # IDEs and editors
15 | .idea/
16 | .project
17 | .classpath
18 | .c9/
19 | *.launch
20 | .settings/
21 | *.sublime-workspace
22 |
23 | # Visual Studio Code
24 | .vscode/*
25 | !.vscode/settings.json
26 | !.vscode/tasks.json
27 | !.vscode/launch.json
28 | !.vscode/extensions.json
29 | .history/*
30 |
31 | # Miscellaneous
32 | /.angular/cache
33 | .sass-cache/
34 | /connect.lock
35 | /coverage
36 | /libpeerconnection.log
37 | testem.log
38 | /typings
39 |
40 | # System files
41 | .DS_Store
42 | Thumbs.db
43 |
44 | # Firebase
45 | .firebase
46 | *-debug.log
47 | .runtimeconfig.json
48 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
3 | "recommendations": ["angular.ng-template"]
4 | }
5 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
3 | "version": "0.2.0",
4 | "configurations": [
5 | {
6 | "name": "ng serve",
7 | "type": "chrome",
8 | "request": "launch",
9 | "preLaunchTask": "npm: start",
10 | "url": "http://localhost:4200/"
11 | },
12 | {
13 | "name": "ng test",
14 | "type": "chrome",
15 | "request": "launch",
16 | "preLaunchTask": "npm: test",
17 | "url": "http://localhost:9876/debug.html"
18 | }
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | // For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
3 | "version": "2.0.0",
4 | "tasks": [
5 | {
6 | "type": "npm",
7 | "script": "start",
8 | "isBackground": true,
9 | "problemMatcher": {
10 | "owner": "typescript",
11 | "pattern": "$tsc",
12 | "background": {
13 | "activeOnStart": true,
14 | "beginsPattern": {
15 | "regexp": "(.*?)"
16 | },
17 | "endsPattern": {
18 | "regexp": "bundle generation complete"
19 | }
20 | }
21 | }
22 | },
23 | {
24 | "type": "npm",
25 | "script": "test",
26 | "isBackground": true,
27 | "problemMatcher": {
28 | "owner": "typescript",
29 | "pattern": "$tsc",
30 | "background": {
31 | "activeOnStart": true,
32 | "beginsPattern": {
33 | "regexp": "(.*?)"
34 | },
35 | "endsPattern": {
36 | "regexp": "bundle generation complete"
37 | }
38 | }
39 | }
40 | }
41 | ]
42 | }
43 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | Copyright 2023 MongoDB Inc.
179 |
180 | Licensed under the Apache License, Version 2.0 (the "License");
181 | you may not use this file except in compliance with the License.
182 | You may obtain a copy of the License at
183 |
184 | http://www.apache.org/licenses/LICENSE-2.0
185 |
186 | Unless required by applicable law or agreed to in writing, software
187 | distributed under the License is distributed on an "AS IS" BASIS,
188 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189 | See the License for the specific language governing permissions and
190 | limitations under the License.
191 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Generative AI Sentiment Analysis and Summarization
2 |
3 | This is a demo of a sentiment analysis, tagging, and summarization Gemini — Google's next-generation AI model.
4 |
5 | ## Quickstart
6 |
7 | ### Google Cloud setup
8 | Create two public 2nd generation Cloud Functions with the following implementations.
9 |
10 | 1. [Analyze sentiment Google Cloud Function](./google-cloud-functions/analyze-sentiment/)
11 | 1. [Summarize reviews Google Cloud Function](./google-cloud-functions/summarize-review-sentiment/)
12 |
13 | Take a note of the deployed functions' URLs. You will need them later.
14 |
15 | ### MongoDB Atlas setup
16 |
17 | 1. Create a [free MongoDB Atlas account](https://mongodb.com/try?utm_campaign=devrel&utm_source=google.cloud&utm_medium=github&utm_content=sentiment.chef&utm_term=stanimira.vlaeva).
18 | 1. Database cluster
19 | - Deploy a new MongoDB database cluster in your Atlas account. You can use the free M0 tier for this demo.
20 | - Load the sample dataset.
21 | 1. Data API
22 | - Enable the Data API for your newly deployed cluster.
23 | - Set the `readAll` data access rule for the `sample_restaurants.restaurants` collection.
24 | 1. Atlas Functions
25 | - Create two new Atlas Functions with the following implementations. Replace the URL placeholders with the URls of the deployed Google Cloud Functions.
26 | - [Analyze sentiment Atlas Function](./atlas-app-services/functions/Atlas_Triggers_analyzeReviewSentiment_1686394580.js)
27 | - [Summarize reviews Atlas Function](./atlas-app-services/functions/Atlas_Triggers_summarizeReviewsSentiment_1686475894.js)
28 | 1. Atlas Triggers
29 | - Create two new Atlas Triggers with the following configuration.
30 | - [Analyze sentiment Atlas Trigger](./atlas-app-services/triggers/analyzeReviewSentiment.json)
31 | - [Summarize reviews Atlas Trigger](./atlas-app-services/triggers/summarizeReviewsSentiment.json)
32 |
33 | ## Contributors ✨
34 |
35 |
36 |
37 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/app/media-upload-dialog/media-upload-dialog.component.scss:
--------------------------------------------------------------------------------
1 | .dialog-container {
2 | min-width: 1000px;
3 | min-height: 500px;
4 | }
5 |
6 | h2 {
7 | font-size: 30px !important;
8 | margin: 30px;
9 | }
10 |
11 | .media-preview {
12 | margin: 20px 0;
13 | grid-gap: 16px 16px;
14 | display: flex;
15 | flex-direction: column;
16 | gap: 30px;
17 |
18 | .media-row {
19 | display: grid;
20 | grid-template-columns: 1fr 2fr;
21 | gap: 30px;
22 | }
23 |
24 | .media-preview {
25 | justify-self: center;
26 | }
27 |
28 | .description {
29 | display: flex;
30 | flex-direction: column;
31 | justify-content: center;
32 | gap: 5px;
33 | max-width: 600px;
34 |
35 | h3 {
36 | font-weight: bold;
37 | font-size: 18px;
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/src/app/media-upload-dialog/media-upload-dialog.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, Inject } from '@angular/core';
2 | import { MAT_DIALOG_DATA } from '@angular/material/dialog';
3 | import { ImageUploaderService } from '../image-uplouder.service';
4 | import { UploadedMedia } from '../uploaded-media';
5 | import { FileHandle } from '../file-handle.service';
6 |
7 | export interface MediaUploadDialogData {
8 | fileHandles: FileHandle[];
9 | }
10 |
11 | @Component({
12 | selector: 'app-media-upload-dialog',
13 | templateUrl: './media-upload-dialog.component.html',
14 | styleUrls: ['./media-upload-dialog.component.scss']
15 | })
16 | export class MediaUploadDialogComponent {
17 | fileHandles: FileHandle[] = [];
18 | uploading = false;
19 | allFailed = false;
20 | uploadedImages: Array = [];
21 |
22 | constructor(
23 | @Inject(MAT_DIALOG_DATA) public data: MediaUploadDialogData,
24 | private imageUploader: ImageUploaderService,
25 | ) {
26 |
27 | this.fileHandles = data.fileHandles;
28 | this.upload();
29 | }
30 |
31 |
32 | upload(): void {
33 | const promises = [];
34 | let failedRequests = 0;
35 | for (let fileHandle of this.fileHandles) {
36 | this.uploading = true;
37 |
38 | const promise = this.imageUploader.upload(fileHandle.file)
39 | .then((result) => {
40 | this.uploadedImages.push({
41 | fileName: result.fileName,
42 | mimeType: fileHandle.file.type,
43 | description: result.analysis?.description || '',
44 | tags: result.analysis?.tags || [],
45 | sentiment: result.analysis?.sentiment || ''
46 | });
47 | })
48 | .catch((error) => {
49 | failedRequests++;
50 | console.error(error);
51 | });
52 |
53 | promises.push(promise);
54 | }
55 |
56 | Promise.all(promises).finally(() => {
57 | this.uploading = false;
58 | });
59 |
60 | if (failedRequests === this.fileHandles.length) {
61 | this.allFailed = true;
62 | }
63 | }
64 | }
65 |
66 |
--------------------------------------------------------------------------------
/src/app/navbar/navbar.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | restaurant_menu
4 | Restaurants
5 |
6 |
7 |
8 |
11 |
12 |
13 |
14 |
15 |
16 |
33 |
34 |
--------------------------------------------------------------------------------
/src/app/navbar/navbar.component.scss:
--------------------------------------------------------------------------------
1 | .spacer {
2 | flex: 1 1 auto;
3 | }
4 |
5 |
6 | .mat-toolbar a {
7 | margin-left: 8px;
8 | color: inherit;
9 | line-height: 18px;
10 | text-decoration: none;
11 | }
12 |
13 | header {
14 | position: fixed;
15 | top: 0;
16 | z-index: 11;
17 | transition: all 400ms ease-in-out;
18 |
19 | .main-header {
20 | @extend header;
21 |
22 | &.hidden {
23 | opacity: 0;
24 | }
25 | }
26 | }
27 |
28 | .search-block {
29 | @extend header;
30 | width: 0%;
31 | right: 0;
32 | background: #fff;
33 |
34 |
35 | &.active {
36 | width: 400px;
37 |
38 | input {
39 | width: 280px;
40 | }
41 | }
42 |
43 | .search-autocomplete-form {
44 | display: flex;
45 |
46 | .search-control {
47 | flex: 1;
48 | font-size: 1rem;
49 | border: 0;
50 | outline: none;
51 | padding-left: 10px;
52 | }
53 | }
54 |
55 | @media only screen and (max-width: 800px) {
56 | &.active, .search-autocomplete-form {
57 | width: 100%;
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/src/app/navbar/navbar.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { ComponentFixture, TestBed } from '@angular/core/testing';
2 |
3 | import { NavbarComponent } from './navbar.component';
4 |
5 | describe('NavbarComponent', () => {
6 | let component: NavbarComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [NavbarComponent]
12 | });
13 | fixture = TestBed.createComponent(NavbarComponent);
14 | component = fixture.componentInstance;
15 | fixture.detectChanges();
16 | });
17 |
18 | it('should create', () => {
19 | expect(component).toBeTruthy();
20 | });
21 | });
22 |
--------------------------------------------------------------------------------
/src/app/navbar/navbar.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
2 | import { FormBuilder, Validators, FormControl } from '@angular/forms';
3 | import { Router } from '@angular/router';
4 | import { Observable, filter, debounceTime, distinctUntilChanged, switchMap } from 'rxjs';
5 | import { Restaurant } from '../restaurant';
6 | import { RestaurantService } from '../restaurant.service';
7 |
8 | @Component({
9 | selector: 'app-navbar',
10 | templateUrl: './navbar.component.html',
11 | styleUrls: ['./navbar.component.scss']
12 | })
13 | export class NavbarComponent implements OnInit {
14 | username = '';
15 | @ViewChild('searchbar') searchBar: ElementRef;
16 |
17 | toggleSearch: boolean = false;
18 | itemOptions: Observable;
19 |
20 | searchForm = this.fb.group({
21 | query: ['', Validators.required],
22 | });
23 |
24 | constructor(
25 | private fb: FormBuilder,
26 | private restaurantService: RestaurantService,
27 | private router: Router
28 | ) {
29 |
30 | this.itemOptions = this.search(this.searchForm.controls.query);
31 | }
32 |
33 | ngOnInit(): void {
34 | }
35 |
36 | openSearch() {
37 | this.toggleSearch = true;
38 | this.searchBar.nativeElement.focus();
39 | }
40 |
41 | searchClose() {
42 | this.searchForm.patchValue({
43 | query: ''
44 | }, { emitEvent: false });
45 | this.toggleSearch = false;
46 | }
47 |
48 | itemSelected(event: any) {
49 | const item = event.option.value;
50 | if (!item || !item._id) {
51 | return;
52 | }
53 |
54 | // Workaround for https://github.com/angular/angular/issues/47813
55 | this.router.navigate(['/']).then(_ => {
56 | this.router.navigate([`/restaurants/${item._id}`]);
57 | })
58 |
59 | this.searchClose();
60 | }
61 |
62 | displayName(item: any) {
63 | return item.name;
64 | }
65 |
66 | private search(formControl: FormControl) {
67 | return formControl.valueChanges.pipe(
68 | filter(text => text!.length > 1),
69 | debounceTime(250),
70 | distinctUntilChanged(),
71 | switchMap(searchTerm => this.restaurantService.search(searchTerm!)),
72 | );
73 | }
74 | }
--------------------------------------------------------------------------------
/src/app/realm-app.service.ts:
--------------------------------------------------------------------------------
1 | import * as Realm from 'realm-web';
2 | import { Injectable } from '@angular/core';
3 | import { config } from '../config';
4 |
5 | @Injectable({
6 | providedIn: 'root'
7 | })
8 | export class RealmAppService {
9 | private static app: Realm.App;
10 |
11 | async getAppInstance() {
12 | if (!RealmAppService.app) {
13 | RealmAppService.app = new Realm.App({ id: config.realmAppId });
14 |
15 | const credentials = Realm.Credentials.anonymous();
16 | await RealmAppService.app.logIn(credentials);
17 | }
18 |
19 | return RealmAppService.app;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/app/restaurant-details-guided/restaurant-details-guided.component.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/src/app/restaurant-details-guided/restaurant-details-guided.component.scss:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mongodb-developer/Google-Cloud-Sentiment-Chef/6d2e932544dc6b4ea45b5c71bbd9ebd74c93c02a/src/app/restaurant-details-guided/restaurant-details-guided.component.scss
--------------------------------------------------------------------------------
/src/app/restaurant-details-guided/restaurant-details-guided.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, EventEmitter, Input, Output } from '@angular/core';
2 | import { GuidedTour, Orientation, GuidedTourService } from 'ngx-guided-tour';
3 | import { Restaurant } from '../restaurant';
4 | import { NewReview, RawReview } from '../review';
5 | import { BehaviorSubject } from 'rxjs';
6 |
7 | export interface ReviewFormState {
8 | review?: Partial,
9 | attachImages?: boolean,
10 | submitReview?: boolean,
11 | }
12 |
13 | const reviews: NewReview[] = [
14 | {
15 | name: 'Clementine',
16 | text: `Incredible place. I would love to visit again. This is a very nice restaurant with tasty creative food and attentive staff. The food is delicious, with a nice twist of the original recipes. The staff is very nice, not only they advised me on a the choice of dishes and desert, but even brought me an Ethiopian desert after I had a question. Would definitely come again!`,
17 | date: new Date().toString()
18 | },
19 | {
20 | name: 'Mary',
21 | text: `Went here for an early dinner last night. Don't drive here. Parking is terrible. Seated promptly. No liquor license yet. We didn't enjoy it at all and the service wasn't great either. The food was mediocre.`,
22 | date: new Date().toString()
23 | },
24 | {
25 | name: 'Joel',
26 | text: `We came here for drinks.`,
27 | date: new Date().toString()
28 | },
29 | {
30 | name: 'Joel',
31 | text: `We came here for drinks.`,
32 | date: new Date().toString(),
33 | images: [
34 | {
35 | fileName: 'https://i.ibb.co/pvQtyx7/fun-1.jpg',
36 | mimeType: 'image/jpeg'
37 | },
38 | {
39 | fileName: 'https://i.ibb.co/K9SL0SR/stock-photo-1.jpg',
40 | mimeType: 'image/jpeg'
41 | },
42 | {
43 | fileName: 'https://i.ibb.co/k4z8SGs/fun-2.jpg',
44 | mimeType: 'image/jpeg'
45 | },
46 | ]
47 | },
48 | ];
49 |
50 | @Component({
51 | selector: 'app-restaurant-details-guided',
52 | templateUrl: './restaurant-details-guided.component.html',
53 | styleUrls: ['./restaurant-details-guided.component.scss']
54 | })
55 | export class RestaurantDetailsGuidedComponent {
56 | currentReview: NewReview;
57 | reviewsCounter = 0;
58 | toursCounter = 0;
59 |
60 | @Input() restaurant: Restaurant;
61 | @Input() reviewFormState: BehaviorSubject = new BehaviorSubject({});
62 | @Input() searchState: BehaviorSubject = new BehaviorSubject('');
63 |
64 | tours: GuidedTour[] = [
65 | {
66 | tourId: 'review-1-submit',
67 | useOrb: true,
68 | steps: [
69 | {
70 | title: 'Restaurant Page: Unleash the full potential of Sentiment Chef!',
71 | selector: '.restaurant-name',
72 | content: 'This page is the beating heart of the Sentiment Chef demo. Click \'Next\' to embark on an exciting exploration of its features!',
73 | orientation: Orientation.Bottom,
74 | useHighlightPadding: true,
75 | },
76 | {
77 | title: 'Restaurant Details',
78 | selector: '.restaurant-details',
79 | content: 'The information on this page, including cuisine, neighborhood, and description, is fetched from a MongoDB Atlas database.',
80 | orientation: Orientation.Bottom,
81 | useHighlightPadding: true,
82 | },
83 | {
84 | title: 'AI-powered Reviews',
85 | selector: '.restaurant-review-form',
86 | content: 'Let\'s fill out a customer review to witness the capabilities of AI-driven sentiment analysis.',
87 | closeAction: () => this.fillOutReview(),
88 | orientation: Orientation.Right,
89 | useHighlightPadding: true
90 | },
91 | {
92 | selector: '.restaurant-review-form',
93 | content: 'Click the \'Done\' button to submit the review and wait for the AI model to analyse it!',
94 | closeAction: () => {
95 | this.submitReview();
96 |
97 | // Wait for the first review to be analysed
98 | setTimeout(() => {
99 | this.startNextTour();
100 | }, 3000);
101 | },
102 | orientation: Orientation.Right,
103 | useHighlightPadding: true
104 | },
105 | ]
106 | },
107 | {
108 | tourId: 'review-1-tour',
109 | steps: [
110 | {
111 | selector: '.first-review',
112 | content: 'Gemini analysed the sentiment of your review!',
113 | orientation: Orientation.Right,
114 | useHighlightPadding: true,
115 | },
116 | {
117 | selector: '.first-review .restaurant-review-details-header',
118 | content: 'The review has been assigned a sentiment label.',
119 | orientation: Orientation.Bottom,
120 | useHighlightPadding: true,
121 | },
122 | {
123 | selector: '.first-review .restaurant-review-scores',
124 | content: 'The sentiment of the review has been evaluated across three distinct categories with scores from 1 to 5.',
125 | orientation: Orientation.Bottom,
126 | useHighlightPadding: true,
127 | closeAction: () => this.startNextTour(),
128 | },
129 | ]
130 | },
131 |
132 | {
133 | tourId: 'review-2-submit',
134 | steps: [
135 | {
136 | selector: '.restaurant-review-form',
137 | content: 'Let\'s put the AI model to the test with a more negative review.',
138 | closeAction: () => this.fillOutReview(),
139 | orientation: Orientation.Right,
140 | useHighlightPadding: true
141 | },
142 | {
143 | selector: '.restaurant-review-form',
144 | content: 'Click the \'Done\' button to submit the review and wait for the AI model to analyse it!',
145 | closeAction: () => {
146 | this.submitReview();
147 | this.startNextTour();
148 | },
149 | orientation: Orientation.Right,
150 | useHighlightPadding: true
151 | },
152 | ]
153 | },
154 |
155 | {
156 | tourId: 'review-2-tour',
157 | steps: [
158 | {
159 | selector: '.first-review',
160 | content: 'The sentiment analysis is different this time.',
161 | orientation: Orientation.Right,
162 | useHighlightPadding: true,
163 | },
164 | {
165 | selector: '.first-review .restaurant-review-details-header',
166 | content: 'The sentiment of the review was notably negative as indicated by the AI model.',
167 | orientation: Orientation.Bottom,
168 | useHighlightPadding: true,
169 | },
170 | {
171 | selector: '.first-review .restaurant-review-scores',
172 | content: 'The category scores are also low.',
173 | orientation: Orientation.Bottom,
174 | useHighlightPadding: true,
175 | closeAction: () => this.startNextTour(),
176 | },
177 | ]
178 | },
179 |
180 | {
181 | tourId: 'review-3-submit',
182 | steps: [
183 | {
184 | selector: '.restaurant-review-form',
185 | content: 'Let\'s put the AI model to one more test.',
186 | closeAction: () => this.fillOutReview(),
187 | orientation: Orientation.Right,
188 | useHighlightPadding: true
189 | },
190 | {
191 | selector: '.restaurant-review-form',
192 | content: 'Click the \'Done\' button to submit the review and wait for the AI model to analyse it!',
193 | closeAction: () => {
194 | this.submitReview();
195 | this.startNextTour();
196 | },
197 | orientation: Orientation.Right,
198 | useHighlightPadding: true
199 | },
200 | ]
201 | },
202 |
203 | {
204 | tourId: 'review-3-tour',
205 | steps: [
206 | {
207 | selector: '.first-review',
208 | content: 'This review was too succinct for the AI model to determine the sentiment. However, people quite often leave short reviews but attach images. Photos can also carry sentiment! Let\'s see what happens if we attach some photos to the same review and submit it again.',
209 | orientation: Orientation.Right,
210 | useHighlightPadding: true,
211 | closeAction: () => this.startNextTour(),
212 | },
213 | ]
214 | },
215 |
216 | {
217 | tourId: 'review-4-fill-out',
218 | steps: [
219 | {
220 | selector: '.restaurant-review-form',
221 | content: 'Let\'s submit the same review but this time attach some photos to it!',
222 | closeAction: async () => {
223 | this.fillOutReview();
224 | setTimeout(() => {
225 | this.startNextTour();
226 | }, 3000);
227 | },
228 | orientation: Orientation.Right,
229 | useHighlightPadding: true
230 | }
231 | ]
232 | },
233 |
234 | {
235 | tourId: 'media-upload-tour',
236 | steps: [
237 | {
238 | selector: '.media-upload-dialog',
239 | content: 'The attached photos may take a couple of seconds to upload. Click \'Next\' after they have been uploaded.',
240 | orientation: Orientation.Right,
241 | useHighlightPadding: true
242 | },
243 | {
244 | selector: '.media-upload-dialog',
245 | content: 'The AI model can detect objects and sentiment in the images. It has generated a description, extracted useful tags and analysed the sentiment of the images. This data will be used to enhance the sentiment analysis of the whole review.',
246 | orientation: Orientation.Right,
247 | useHighlightPadding: true,
248 | closeAction: () => {
249 | this.attachPhotos();
250 | this.startNextTour();
251 | },
252 | },
253 | ]
254 | },
255 | {
256 | tourId: 'review-4-submit',
257 | steps: [
258 | {
259 | selector: '.restaurant-review-form',
260 | content: 'The images have been attached to the review. Click the \'Done\' button to submit the review and wait for the AI model to analyse it!',
261 | closeAction: () => {
262 | this.submitReview();
263 | this.startNextTour();
264 | },
265 | orientation: Orientation.Right,
266 | useHighlightPadding: true
267 | }
268 | ]
269 | },
270 | {
271 | tourId: 'review-4-tour',
272 | steps: [
273 | {
274 | selector: '.first-review',
275 | content: 'This time, depending on the result we get from the AI model, we might see a different sentiment label for the review.',
276 | orientation: Orientation.Right,
277 | useHighlightPadding: true,
278 | closeAction: () => this.startNextTour(),
279 | },
280 | ]
281 | },
282 |
283 | {
284 | tourId: 'search',
285 | steps: [
286 | {
287 | selector: '.search-form',
288 | content: 'The application uses MongoDB Atlas Search to provide a powerful search functionality. The search utilises not only the reviews text but also extracted image tags and descriptions.',
289 | orientation: Orientation.Bottom,
290 | useHighlightPadding: true,
291 | },
292 | {
293 | selector: '.search-form',
294 | content: 'Let\'s try searching for a review with a specific keyword.',
295 | orientation: Orientation.Bottom,
296 | useHighlightPadding: true,
297 | closeAction: () => {
298 | this.search('beer');
299 | setTimeout(() => {
300 | this.startNextTour();
301 | }, 1000);
302 | }
303 | },
304 | ]
305 | },
306 |
307 | {
308 | tourId: 'search-results',
309 | steps: [
310 | {
311 | selector: '.first-review',
312 | content: 'Even though the text doesn\'t mention beer, the AI model has detected beer in the images and extracted it as a tag. Atlas Search indexes the image tags together with the review texts. This is why the review was returned in the search results.',
313 | orientation: Orientation.Right,
314 | useHighlightPadding: true,
315 | closeAction: () => this.startNextTour(),
316 | },
317 | ]
318 | },
319 |
320 | {
321 | tourId: 'summarization-tour',
322 | steps: [
323 | {
324 | selector: '.restaurant-card-summary',
325 | content: 'Final AI treat! Based on the reviews we just wrote, the AI model also generated a summary for the restaurant.',
326 | orientation: Orientation.Left,
327 | useHighlightPadding: true,
328 | },
329 | ]
330 | },
331 | ];
332 |
333 | constructor(
334 | private guidedTourService: GuidedTourService,
335 | ) {
336 | }
337 |
338 | async ngOnInit(): Promise {
339 | this.startNextTour();
340 | }
341 |
342 | private fillOutReview() {
343 | this.currentReview = reviews[this.reviewsCounter++];
344 | this.reviewFormState.next({ review: this.currentReview });
345 |
346 | setTimeout(() => {
347 | // wait before showing the next step in the guide
348 | }, 1000);
349 | }
350 |
351 | submitReview() {
352 | this.currentReview = { name: '', text: '', date: new Date().toString() };
353 | this.reviewFormState.next({ submitReview: true });
354 | }
355 |
356 | attachPhotos() {
357 | this.reviewFormState.next({ attachImages: true });
358 | }
359 |
360 | search(query: string) {
361 | this.searchState.next(query);
362 | }
363 |
364 | private startNextTour() {
365 | setTimeout(() => {
366 | const nextTour = this.tours[this.toursCounter++];
367 | this.guidedTourService.startTour(nextTour);
368 | }, 3000);
369 | }
370 | }
371 |
--------------------------------------------------------------------------------
/src/app/restaurant-details/restaurant-details.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
Overview
13 |
14 |
15 |
16 |
17 |
{{ restaurant.name }}
18 |
19 |
20 |
21 |
🍽️ {{ restaurant.cuisine }}
22 |
📍 {{ restaurant.borough }}
23 |
24 |
25 |
26 |
27 | Nestled in the heart of a bustling city, the gastronomic paradise of "Flavorsome Haven"
28 | beckons food enthusiasts with
29 | its enchanting ambiance and delectable culinary offerings.
30 | As you step through the entrance, you're greeted by an elegant and modern interior that
31 | exudes a warm and inviting atmosphere.
32 |