flutter-ml / google_ml_kit_flutter

A flutter plugin that implements Google's standalone ML Kit
MIT License
952 stars 727 forks source link

No result downloading English Translation #496

Open codemaster-mo opened 1 year ago

codemaster-mo commented 1 year ago

var modelManager = OnDeviceTranslatorModelManager();

modelManager .downloadModel(TranslateLanguage.english.bcpCode) .then((value) => { englishTranlationDownloaded = value, print('Download english result: ' + value.toString()) }) .onError((error, stackTrace) => { print(error) });

modelManager.downloadModel(TranslateLanguage.arabic.bcpCode).then((value) => { arabicTranlationDownloaded = value, print('Download arabic result: ' + value.toString()) });

  I get a result back for Arabic but not for English. It seems to take forever to get the result. The same code works fine on Android.

google_mlkit_commons: ^0.5.0 google_mlkit_language_id: ^0.8.0 google_mlkit_translation: ^0.8.0

codemaster-mo commented 1 year ago

flutter: Download german result: true flutter: Download spanish result: true flutter: Download chinese result: true flutter: Download arabic result: true

Other Languages seem to work?

ben2002chou commented 1 year ago

same here. I also get these lines repeatedly: I0000 00:00:1690653847.667606 20 hmm_decoder_wrapper.cc:74] Successfully enrolled hmm decoder transliterator for the language pair: (zh,en). W0000 00:00:1690653847.667872 20 hmm_engine.cc:2082] Unable to get language model data setting I0000 00:00:1690653847.668078 20 dictionary.cc:266] Dictionary build date: 20191024 failed to get XNNPACK profile information. ERROR: failed to get XNNPACK profile information.

codemaster-mo commented 1 year ago

The funny part is the following:

englishTranlationDownloaded = await modelManager.isModelDownloaded(TranslateLanguage.english.bcpCode);

It seems to always returns true. For other languages if it's not downloaded it returns false.

I have gone and tried implementing it directly into Swift. Here I also see the same behaviour where it will never return a result.

`func translate() -> String { var stringToTranslate = "input" // Default to the original input in case of an error or if the translation is not completed yet. var translatedString = stringToTranslate let dispatchGroup = DispatchGroup() dispatchGroup.enter()

stringToTranslate.translateToArabic { result in
    switch result {
    case .failure(let error):
        print("There was an error \(error)")
    case .success(let translated):
        print("The translated string is: \(translated)")
        translatedString = translated
    }

    dispatchGroup.leave()
}

dispatchGroup.wait() // Wait for the translation to complete.

return translatedString

}

extension String { func translateToArabic(completionHandler: @escaping (Result<String, Error>) -> Void) { let options = TranslatorOptions(sourceLanguage: .english, targetLanguage: .arabic)

    let translatorForDownloading = Translator.translator(options: options)

    translatorForDownloading.downloadModelIfNeeded { error in
        guard error == nil else {
            completionHandler(.failure(error!))
            return
        }

        translatorForDownloading.translate(self) { result, error in
            guard error == nil else {
                completionHandler(.failure(error!))
                return
            }
            completionHandler(.success(result!))
        }
    }
}

}`

codemaster-mo commented 1 year ago

I decided to test it on TestFlight it works just fine there. So is an issue on emulator only?

fbernaly commented 1 year ago

What I have seen in our example app is that it always returns true for English, even if I delete it, and then I check if it exists it returns true so, I believe it is bundled with the SDK since it is the base language. So you do not need to download English, it is be always be available.,

github-actions[bot] commented 5 months ago

This issue is stale because it has been open for 30 days with no activity.