0812
This commit is contained in:
27
lib/services/classification_service.dart
Normal file
27
lib/services/classification_service.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class TextClassificationService {
|
||||
Future<int> classifyText(String text) async {
|
||||
try {
|
||||
final uri = Uri.parse('http://143.64.185.20:18606/classify');
|
||||
|
||||
final response = await http.post(
|
||||
uri,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: json.encode({'text': text}),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
return json.decode(response.body)['category'];
|
||||
} else {
|
||||
print(
|
||||
'Classification failed: ${response.statusCode}, ${response.body}');
|
||||
return -1;
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error during text classification: $e');
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user