I want to make a chatbot by using GEMINI API for a fund advisor in flutter but i want to make Gemini read that xlsx file and respond me by reading that. But I failed always. There are instances at python or javascript but i cant find it for flutter
void _sendMessage() async {
try {
final messageText = _controller.text.trim();
if (messageText.isEmpty) return;
_controller.clear();
setState(() {
_messages.add(Message(text: messageText, isUser: true));
_isLoading = true; // Set loading state when sending message
});
_scrollToBottom();
final model = GenerativeModel(
model: 'gemini-pro',
apiKey: 'API-KEY');
final content = [Content.text(messageText)];
final response = await model.generateContent(content);
setState(() {
_messages.add(Message(text: response.text!, isUser: false));
_isLoading = false; // Clear loading state after receiving response
});
_scrollToBottom();
_controller.clear();
} catch (e) {
log("Error : $e");
setState(() {
_isLoading = false; // Ensure loading state is cleared on error
});
}
}
thats my message code im sending gemini messages and getting responds from here and I tried file reading by that code
final geminiApi = GeminiApi('API-KEY');
const filePath = 'assets/data.xlsx';
const mimeType = 'application/vnd.google-apps.spreadsheet';
// Upload the file
final fileResponse = await geminiApi.uploadFile(filePath, mimeType);
final fileId = fileResponse['id'];
// Wait for the file to be processed
await geminiApi.waitForFileProcessing(fileId);
thats for i tried make it read from that code but it didnt work
New contributor
Mert Miraç Arık is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.