ammargitham / WallFlow

Wallpaper app for Android using Jetpack Compose
GNU General Public License v3.0
325 stars 18 forks source link

[Bug (Plus)] Unable to download TFLite model #65

Closed RobBrazier closed 5 months ago

RobBrazier commented 7 months ago

Android 14 (Pixel 7a and Samsung S23 OneUI 6.0)

I think either after the move from TFHub -> Kaggle, or in a recent release, something has changed in the downloading of models from tfhub.dev - even the EfficentDet-Lite0 model cannot be downloaded

I managed to get the below log from logcat, weirdly I am able to download it from my browser though and it's coming down as 1.tflite as the filename (at first I was thinking they completely broke the download URLs on the move, but thankfully not)

doWork: Error downloading https://tfhub.dev/tensorflow/lite-model/efficientdet/lite0/detection/metadata/1?lite-format=tflite
java.lang.IllegalArgumentException: Could not parse file name from response
    at kotlin.ResultKt.createFile(SourceFile:41)
    at kotlin.ResultKt.download(SourceFile:310)
    at com.ammar.wallflow.workers.HelpersKt$download$1.invokeSuspend(Unknown Source:15)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(Unknown Source:8)
    at kotlinx.coroutines.DispatchedTask.run(Unknown Source:96)
    at androidx.work.Worker$2.run(SourceFile:31)
    at kotlinx.coroutines.scheduling.TaskImpl.run(Unknown Source:2)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(SourceFile:92)

I'll have a go through the source to see if I can spot where it might be going wrong, but thought I'd raise it first

I've tried this on a Google Pixel 7a and Samsung Galaxy S23 and they are both having the same issue (although I was only able to try downloading a 'custom' tflite model instead of the default one on the S23)

I also tried uploading the 1.tflite file to an object storage bucket to download from there and that also didn't work though - same error

RobBrazier commented 7 months ago

I tried downgrading as far as 2.0.0 to test and still seeing this same exception - also wiped data on the S23 and seeing the same, will try downgrading on the S23 as well just to try and reduce the likelihood of device issues (as I know it used to work on the S23, but Pixel 7a is new and hasn't worked yet)

EDIT: I think a version regression can be ruled out - must be that something changed upstream (tried all the way back to 1.3.1 which I think is when I started using the app) or something android 14 related maybe?

ammargitham commented 7 months ago

Hi. I'm travelling currently. Will check this when I'm back.

Although I can mention that I try to get the file name from the response content disposition header. Maybe something has changed there.

RobBrazier commented 7 months ago

No worries, yeah looks like it has been stripped out then - the final response after redirecting twice is

HTTP/2 200
x-guploader-uploadid: ABPtcPowZfJzjProtoQpSTU3PYKnhaWuSfQpC9MFHX8i6Y9fktwRMRCumoNNlghb-6sSjH4BIUzVCEjfjw
expires: Sat, 20 Jan 2024 20:13:51 GMT
date: Sat, 20 Jan 2024 20:13:51 GMT
cache-control: private, max-age=0
last-modified: Thu, 12 Jan 2023 01:24:26 GMT
etag: "db64092e90738511b421e960103ad4c2"
x-goog-generation: 1673486666597030
x-goog-metageneration: 1
x-goog-stored-content-encoding: identity
x-goog-stored-content-length: 4563519
content-type: application/octet-stream
x-goog-hash: crc32c=Tz+1/w==
x-goog-hash: md5=22QJLpBzhRG0IelgEDrUwg==
x-goog-storage-class: REGIONAL
accept-ranges: bytes
content-length: 4563519
vary: Origin
server: UploadServer
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000

It's coming from a google storage URL (after redirecting to https://www.kaggle.com/models/tensorflow/efficientdet/frameworks/tfLite/variations/lite0-detection-metadata/versions/1?lite-format=tflite&tfhub-redirect=true)

I assume the browser is able to get the filename because it actually ends up being in the URL (https://storage.googleapis.com/kagglesdsdata/models/992/1146/1.tflite with a bunch of pre-signed URL query params too)

RobBrazier commented 7 months ago

I've managed to get it working and raised a PR, as it mentions in the description, feel free to use it if you wish, or do your own implementation :smile:

ammargitham commented 6 months ago

Thanks for the PR. Will review it in the coming days and merge it.

ammargitham commented 5 months ago

Fixed by #66