Oviya
commited on
Commit
·
43f0ed7
1
Parent(s):
c39ef1c
findwordfix
Browse files
package-lock.json
CHANGED
|
@@ -41,6 +41,9 @@
|
|
| 41 |
"karma-jasmine": "~5.1.0",
|
| 42 |
"karma-jasmine-html-reporter": "~2.1.0",
|
| 43 |
"typescript": "~5.3.2"
|
|
|
|
|
|
|
|
|
|
| 44 |
}
|
| 45 |
},
|
| 46 |
"node_modules/@alloc/quick-lru": {
|
|
|
|
| 41 |
"karma-jasmine": "~5.1.0",
|
| 42 |
"karma-jasmine-html-reporter": "~2.1.0",
|
| 43 |
"typescript": "~5.3.2"
|
| 44 |
+
},
|
| 45 |
+
"engines": {
|
| 46 |
+
"node": ">=18"
|
| 47 |
}
|
| 48 |
},
|
| 49 |
"node_modules/@alloc/quick-lru": {
|
src/app/findword/findword.component.ts
CHANGED
|
@@ -69,9 +69,9 @@ export class FindwordComponent {
|
|
| 69 |
this.wordSentence = response.sentence;
|
| 70 |
console.log("✅ Correct Word Set:", this.correctWord);
|
| 71 |
|
| 72 |
-
|
| 73 |
-
this.audioUrl =
|
| 74 |
-
|
| 75 |
|
| 76 |
this.cd.detectChanges();
|
| 77 |
|
|
|
|
| 69 |
this.wordSentence = response.sentence;
|
| 70 |
console.log("✅ Correct Word Set:", this.correctWord);
|
| 71 |
|
| 72 |
+
// ✅ use service helper (works on local & HF)
|
| 73 |
+
this.audioUrl = this.findwordService.buildAssetUrl(response.audio_file_path);
|
| 74 |
+
|
| 75 |
|
| 76 |
this.cd.detectChanges();
|
| 77 |
|
src/app/findword/findword.service.ts
CHANGED
|
@@ -6,17 +6,29 @@ import { Observable } from 'rxjs';
|
|
| 6 |
providedIn: 'root'
|
| 7 |
})
|
| 8 |
export class FindwordService {
|
| 9 |
-
private
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
constructor(private http: HttpClient) { }
|
| 11 |
|
| 12 |
// Fetches the audio file from backend
|
| 13 |
fetchAudio(): Observable<any> {
|
| 14 |
-
return this.http.get(`${this.
|
| 15 |
}
|
| 16 |
|
| 17 |
|
| 18 |
// Validates the word entered by the user
|
| 19 |
validateWord(userWord: string, correctWord: string | null): Observable<any> {
|
| 20 |
-
return this.http.post<any>(`${this.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
}
|
|
|
|
| 6 |
providedIn: 'root'
|
| 7 |
})
|
| 8 |
export class FindwordService {
|
| 9 |
+
private readonly baseUrl = location.hostname.endsWith('hf.space')
|
| 10 |
+
? 'https://pykara-py-learn-backend.hf.space/media'
|
| 11 |
+
: 'http://localhost:5000/media';
|
| 12 |
+
|
| 13 |
+
// Origin is needed to serve static assets like /static/audio/...
|
| 14 |
+
private readonly origin = this.baseUrl.replace(/\/media$/, '');
|
| 15 |
+
|
| 16 |
constructor(private http: HttpClient) { }
|
| 17 |
|
| 18 |
// Fetches the audio file from backend
|
| 19 |
fetchAudio(): Observable<any> {
|
| 20 |
+
return this.http.get(`${this.baseUrl}/generate-vocabulary`, { responseType: 'json' });
|
| 21 |
}
|
| 22 |
|
| 23 |
|
| 24 |
// Validates the word entered by the user
|
| 25 |
validateWord(userWord: string, correctWord: string | null): Observable<any> {
|
| 26 |
+
return this.http.post<any>(`${this.baseUrl}/validate-word`, { user_input: userWord, correct_word: correctWord });
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
/** Build full URL for assets returned by backend (e.g., /static/audio/foo.mp3) */
|
| 30 |
+
buildAssetUrl(path: string): string {
|
| 31 |
+
// path is like "/static/audio/<file>.mp3"
|
| 32 |
+
return `${this.origin}${path}`;
|
| 33 |
}
|
| 34 |
}
|