55import android .content .Context ;
66import android .os .Bundle ;
77import android .util .Log ;
8+ import android .util .Pair ;
89import android .view .View ;
910import android .widget .EditText ;
1011import android .widget .ImageButton ;
@@ -110,32 +111,46 @@ protected void onDestroy() {
110111 }
111112
112113 private void downloadModels (Context context ) throws GenAIException {
113- List <String > urls = Arrays .asList (
114- "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/added_tokens.json?download=true" ,
115- "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/config.json?download=true" ,
116- "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/configuration_phi3.py?download=true" ,
117- "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/genai_config.json?download=true" ,
118- "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/phi3-mini-4k-instruct-cpu-int4-rtn-block-32-acc-level-4.onnx?download=true" ,
119- "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/phi3-mini-4k-instruct-cpu-int4-rtn-block-32-acc-level-4.onnx.data?download=true" ,
120- "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/special_tokens_map.json?download=true" ,
121- "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/tokenizer.json?download=true" ,
122- "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/tokenizer.model?download=true" ,
123- "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/tokenizer_config.json?download=true" );
124-
125- List <String > fileNames = Arrays .asList ("added_tokens.json" ,
126- "config.json" , "configuration_phi3.py" , "genai_config.json" ,
127- "phi3-mini-4k-instruct-cpu-int4-rtn-block-32-acc-level-4.onnx" ,
128- "phi3-mini-4k-instruct-cpu-int4-rtn-block-32-acc-level-4.onnx.data" ,
129- "special_tokens_map.json" , "tokenizer.model" , "tokenizer.json" ,
130- "tokenizer_config.json" );
131-
132- Toast .makeText (this , "Downloading model for the app... Model Size greater than 2GB, please allow a few minutes to download." , Toast .LENGTH_SHORT ).show ();
114+ List <Pair <String , String >> urlFilePairs = Arrays .asList (
115+ new Pair <>(
116+ "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/added_tokens.json?download=true" ,
117+ "added_tokens.json" ),
118+ new Pair <>(
119+ "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/config.json?download=true" ,
120+ "config.json" ),
121+ new Pair <>(
122+ "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/configuration_phi3.py?download=true" ,
123+ "configuration_phi3.py" ),
124+ new Pair <>(
125+ "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/genai_config.json?download=true" ,
126+ "genai_config.json" ),
127+ new Pair <>(
128+ "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/phi3-mini-4k-instruct-cpu-int4-rtn-block-32-acc-level-4.onnx?download=true" ,
129+ "phi3-mini-4k-instruct-cpu-int4-rtn-block-32-acc-level-4.onnx" ),
130+ new Pair <>(
131+ "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/phi3-mini-4k-instruct-cpu-int4-rtn-block-32-acc-level-4.onnx.data?download=true" ,
132+ "phi3-mini-4k-instruct-cpu-int4-rtn-block-32-acc-level-4.onnx.data" ),
133+ new Pair <>(
134+ "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/special_tokens_map.json?download=true" ,
135+ "special_tokens_map.json" ),
136+ new Pair <>(
137+ "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/tokenizer.json?download=true" ,
138+ "tokenizer.json" ),
139+ new Pair <>(
140+ "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/tokenizer.model?download=true" ,
141+ "tokenizer.model" ),
142+ new Pair <>(
143+ "https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/resolve/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/tokenizer_config.json?download=true" ,
144+ "tokenizer_config.json" ));
145+ Toast .makeText (this ,
146+ "Downloading model for the app... Model Size greater than 2GB, please allow a few minutes to download." ,
147+ Toast .LENGTH_SHORT ).show ();
133148
134149 ExecutorService executor = Executors .newSingleThreadExecutor ();
135- for (int i = 0 ; i < urls .size (); i ++) {
150+ for (int i = 0 ; i < urlFilePairs .size (); i ++) {
136151 final int index = i ;
137- String url = urls .get (index );
138- String fileName = fileNames .get (index );
152+ String url = urlFilePairs .get (index ). first ;
153+ String fileName = urlFilePairs .get (index ). second ;
139154 if (fileExists (context , fileName )) {
140155 // Display a message using Toast
141156 Toast .makeText (this , "File already exists. Skipping Download." , Toast .LENGTH_SHORT ).show ();
@@ -153,7 +168,7 @@ private void downloadModels(Context context) throws GenAIException {
153168 @ Override
154169 public void onDownloadComplete () throws GenAIException {
155170 Log .d (TAG , "Download complete for " + fileName );
156- if (index == urls .size () - 1 ) {
171+ if (index == urlFilePairs .size () - 1 ) {
157172 // Last download completed, create GenAIWrapper
158173 genAIWrapper = createGenAIWrapper ();
159174 Log .d (TAG , "All downloads completed" );
0 commit comments