Oviya commited on
Commit
1202633
·
1 Parent(s): 0e5bc5f

add writing component

Browse files
Files changed (1) hide show
  1. src/app/writing/writing.service.ts +8 -3
src/app/writing/writing.service.ts CHANGED
@@ -9,7 +9,12 @@ import { catchError } from 'rxjs/operators';
9
  providedIn: 'root'
10
  })
11
  export class WritingService {
12
- private apiUrl = 'http://localhost:8000/generate-writing-topics'; // Replace with your backend URL
 
 
 
 
 
13
 
14
  constructor(private http: HttpClient) { }
15
 
@@ -18,7 +23,7 @@ export class WritingService {
18
  const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
19
  const body = { grade_level: gradeLevel };
20
 
21
- return this.http.post<{ topic: string }>(this.apiUrl, body, { headers }).pipe(
22
  catchError((error) => {
23
  console.error('Error fetching writing topic:', error);
24
  return throwError(() => new Error('Failed to fetch writing topic. Please try again.'));
@@ -31,7 +36,7 @@ export class WritingService {
31
  const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
32
  const body = { topic, response };
33
 
34
- return this.http.post<{ feedback: string }>('http://localhost:8000/validate-response', body, { headers }).pipe(
35
  catchError((error) => {
36
  console.error('Error validating response:', error);
37
  return throwError(() => new Error('Failed to validate the response. Please try again.'));
 
9
  providedIn: 'root'
10
  })
11
  export class WritingService {
12
+
13
+ private baseUrl = location.hostname.endsWith('hf.space')
14
+ ? 'https://pykara-py-learn-backend.hf.space/media'
15
+ : 'http://localhost:5000/media';
16
+
17
+ //private apiUrl = 'http://localhost:8000/generate-writing-topics'; // Replace with your backend URL
18
 
19
  constructor(private http: HttpClient) { }
20
 
 
23
  const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
24
  const body = { grade_level: gradeLevel };
25
 
26
+ return this.http.post<{ topic: string }>(`${this.baseUrl}/generate-writing-topics`, body, { headers }).pipe(
27
  catchError((error) => {
28
  console.error('Error fetching writing topic:', error);
29
  return throwError(() => new Error('Failed to fetch writing topic. Please try again.'));
 
36
  const headers = new HttpHeaders({ 'Content-Type': 'application/json' });
37
  const body = { topic, response };
38
 
39
+ return this.http.post<{ feedback: string }>(`${this.baseUrl}/validate-response`, body, { headers }).pipe(
40
  catchError((error) => {
41
  console.error('Error validating response:', error);
42
  return throwError(() => new Error('Failed to validate the response. Please try again.'));