File size: 1,062 Bytes
e4ab6d0
 
 
 
 
 
 
 
 
0759111
 
 
e4ab6d0
 
 
 
 
0759111
e4ab6d0
 
 
0759111
e4ab6d0
 
 
0759111
e4ab6d0
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class ReadingService {

  private baseUrl = location.hostname.endsWith('hf.space')
    ? 'https://pykara-py-learn-backend.hf.space/media'
    : 'http://localhost:5000/media';

  constructor(private http: HttpClient) { }

  // Function to send the topic and difficulty level to the backend and get the generated content
  generateContent(topic: string, difficulty: string): Observable<any> {
    return this.http.post<any>(`${this.baseUrl}/generate_content`, { topic, difficulty });
  }

  generateQuestions(content: string, difficulty: string): Observable<any> {
    return this.http.post<any>(`${this.baseUrl}/generate_questions`, { content, difficulty });
  }

  validateAnswer(question: any, selected_answer: string): Observable<any> {
    return this.http.post<any>(`${this.baseUrl}/validate_answer`, {
      question: question,
      selected_answer: selected_answer
    });
  }
}