py-learn / src /app /reading /reading.service.ts
Oviya
reding component
0e5bc5f
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
});
}
}