Oviya
commited on
Commit
·
756f6d4
1
Parent(s):
ae3eb54
generate question
Browse files
src/app/generate-questions/generate-questions.service.ts
CHANGED
|
@@ -6,28 +6,32 @@ import { Observable } from 'rxjs';
|
|
| 6 |
providedIn: 'root'
|
| 7 |
})
|
| 8 |
export class GenerateQuestionsService {
|
| 9 |
-
private apiUrl = 'http://localhost:5012/generate-questions'; // Backend URL
|
| 10 |
-
private validateAnswerUrl = 'http://localhost:5012/validate-answer';
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
constructor(private http: HttpClient) { }
|
| 14 |
|
| 15 |
// Method to get questions from the backend
|
| 16 |
generateQuestions(topic: string, difficulty: string): Observable<any> {
|
| 17 |
-
|
| 18 |
-
|
| 19 |
}
|
| 20 |
|
| 21 |
-
|
| 22 |
|
| 23 |
// Method to validate the user's answer for a specific question
|
| 24 |
validateAnswer(question: string, userAnswer: string, topic: string): Observable<any> {
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
|
| 29 |
validateAllAnswers(questions: { topic: string; question: string; user_answer: string }[]): Observable<any> {
|
| 30 |
-
return this.http.post<any>(
|
| 31 |
}
|
| 32 |
|
| 33 |
|
|
|
|
| 6 |
providedIn: 'root'
|
| 7 |
})
|
| 8 |
export class GenerateQuestionsService {
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
private baseUrl = location.hostname.endsWith('hf.space')
|
| 11 |
+
? 'https://pykara-py-learn-backend.hf.space/media'
|
| 12 |
+
: 'http://localhost:5000/media';
|
| 13 |
+
|
| 14 |
constructor(private http: HttpClient) { }
|
| 15 |
|
| 16 |
// Method to get questions from the backend
|
| 17 |
generateQuestions(topic: string, difficulty: string): Observable<any> {
|
| 18 |
+
return this.http.post<any>(`${this.baseUrl}/generate-questions`, { topic, difficulty });
|
| 19 |
+
|
| 20 |
}
|
| 21 |
|
| 22 |
+
|
| 23 |
|
| 24 |
// Method to validate the user's answer for a specific question
|
| 25 |
validateAnswer(question: string, userAnswer: string, topic: string): Observable<any> {
|
| 26 |
+
return this.http.post<any>(`${this.baseUrl}/validate-answer`, {
|
| 27 |
+
question,
|
| 28 |
+
user_answer: userAnswer,
|
| 29 |
+
topic
|
| 30 |
+
});
|
| 31 |
}
|
| 32 |
|
| 33 |
validateAllAnswers(questions: { topic: string; question: string; user_answer: string }[]): Observable<any> {
|
| 34 |
+
return this.http.post<any>(`${this.baseUrl}/validate-all-answers`, { questions });
|
| 35 |
}
|
| 36 |
|
| 37 |
|