-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
90 lines (83 loc) · 2.62 KB
/
main.dart
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Professor Recommender',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: RecommendationScreen(),
);
}
}
class RecommendationScreen extends StatefulWidget {
@override
_RecommendationScreenState createState() => _RecommendationScreenState();
}
class _RecommendationScreenState extends State<RecommendationScreen> {
TextEditingController _interestController = TextEditingController();
List<dynamic> _recommendedProfessors = [];
Future<void> _getRecommendations(String interests) async {
String url = 'http://127.0.0.1:5000/recommend_professors_nlp'; // Update this URL
Map<String, String> headers = {"Content-type": "application/json"};
String json = jsonEncode({'interests': interests});
try {
final response = await http.post(Uri.parse(url), headers: headers, body: json);
if (response.statusCode == 200) {
setState(() {
_recommendedProfessors = jsonDecode(response.body);
});
} else {
throw Exception('Failed to load recommendations');
}
} catch (e) {
print('Error: $e');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Professor Recommendations'),
),
body: Padding(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextField(
controller: _interestController,
decoration: InputDecoration(labelText: 'Enter your interests'),
),
SizedBox(height: 20.0),
ElevatedButton(
onPressed: () {
_getRecommendations(_interestController.text);
},
child: Text('Get Recommendations'),
),
SizedBox(height: 20.0),
Expanded(
child: ListView.builder(
itemCount: _recommendedProfessors.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(_recommendedProfessors[index]['name']),
subtitle: Text(_recommendedProfessors[index]['area_of_work']),
);
},
),
),
],
),
),
);
}
}