Skip to content

Commit d6c1ce6

Browse files
Merge pull request #161 from allenai/160-disclose-download-size
Add download disclosure and confirmation
2 parents 1aab96f + f56d9da commit d6c1ce6

File tree

6 files changed

+101
-43
lines changed

6 files changed

+101
-43
lines changed

OLMoE.swift/Constants/AppConstants.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ enum AppConstants {
1212
enum Model {
1313
static let filename = "OLMoE-latest"
1414
static let downloadURL = "https://dolma-artifacts.org/app/\(filename).gguf"
15+
static let playgroundURL = "https://playground.allenai.org/?model=olmoe-0125"
1516
}
1617
}

OLMoE.swift/Constants/Localizable.xcstrings

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@
8080
},
8181
"Proceed With Mocked Model" : {
8282

83+
},
84+
"Start Download" : {
85+
86+
},
87+
"The model requires 4.21GB of storage space. Would you like to proceed with the download?" : {
88+
8389
},
8490
"This device does not have the 8GB physical RAM required to run OLMoE locally." : {
8591

OLMoE.swift/Extensions/DeviceSupport.swift

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,19 @@
99
import SwiftUI
1010
import os
1111

12+
func deviceHasEnoughRam() -> Bool {
13+
let requiredRAM: UInt64 = 6 * 1024 * 1024 * 1024
14+
let totalRAM = ProcessInfo.processInfo.physicalMemory
15+
print("Total RAM (GB)", totalRAM / (1024 * 1024 * 1024))
16+
return totalRAM >= requiredRAM
17+
}
18+
1219
// Device support check function
1320
func isDeviceSupported() -> Bool {
1421
#if targetEnvironment(simulator)
1522
return true
1623
#else
17-
let deviceModel = UIDevice.current.modelName
18-
19-
// Model identifiers for devices with 8GB of RAM or more (iPhones and iPads)
20-
let supportedModels = [
21-
// iPhone models with 8GB RAM
22-
"iPhone16,1", "iPhone16,2", // iPhone 15 Pro and Pro Max
23-
"iPhone17,1", "iPhone17,2", "iPhone17,3", "iPhone17,4", // all iPhone 16 models
24-
25-
// iPad models with 8GB or more RAM
26-
"iPad14,3", "iPad14,4", // iPad Pro 11" 4th Gen
27-
"iPad14,5", "iPad14,6", // iPad Pro 12.9" 6th Gen
28-
"iPad16,3", "iPad16,4", // iPad Pro 11" 5th Gen
29-
"iPad16,5", "iPad16,6", // iPad Pro 12.9" 7th Gen
30-
"iPad13,16", "iPad13,17", // iPad Air 5th Gen
31-
"iPad14,8", "iPad14,9", // iPad Air 6th Gen
32-
"iPad15,1", "iPad15,2", // Hypothetical future iPad models with 8GB RAM
33-
]
34-
35-
return supportedModels.contains(deviceModel)
24+
return deviceHasEnoughRam()
3625
#endif
3726
}
3827

OLMoE.swift/Views/InfoPageView.swift

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,73 @@ struct InfoButton: View {
1616
Image(systemName: "info.circle")
1717
.foregroundColor(Color("TextColor"))
1818
}
19+
.buttonStyle(.plain)
1920
.clipShape(Circle())
20-
.background(
21-
RadialGradient(
22-
gradient: Gradient(colors: [
23-
Color("BackgroundColor").opacity(0.9), Color.clear,
24-
]),
25-
center: .center,
26-
startRadius: 20,
27-
endRadius: 40)
28-
)
21+
.background(Color.clear)
22+
}
23+
}
24+
25+
struct CloseButton: View {
26+
let action: () -> Void
27+
28+
var body: some View {
29+
Button(action: action) {
30+
Image(systemName: "xmark.circle")
31+
.font(.system(size: 20))
32+
.frame(width: 40, height: 40)
33+
.foregroundColor(Color("TextColor"))
34+
}
35+
.buttonStyle(.plain)
36+
.clipShape(Circle())
37+
}
38+
}
39+
40+
struct InfoContent: View {
41+
var body: some View {
42+
VStack(alignment: .leading, spacing: 20) {
43+
ForEach(InfoText.content) { text in
44+
HeaderTextPairView(header: text.header, text: text.text)
45+
.padding([.horizontal], 12)
46+
}
47+
}
48+
.padding([.bottom], 24)
2949
}
3050
}
3151

3252
struct InfoView: View {
3353
@Binding var isPresented: Bool
3454

3555
var body: some View {
56+
#if targetEnvironment(macCatalyst)
57+
VStack(spacing: 0) {
58+
// Fixed header
59+
HStack {
60+
Spacer()
61+
CloseButton(action: { isPresented = false })
62+
}
63+
.padding([.top, .horizontal], 12)
64+
65+
// Scrollable content
66+
ScrollView {
67+
InfoContent()
68+
}
69+
}
70+
#else
3671
ScrollView {
3772
VStack(alignment: .leading, spacing: 20) {
3873
HStack {
3974
Spacer()
40-
Button(action: { isPresented = false }) {
41-
Image(systemName: "xmark.circle")
42-
.font(.system(size: 20))
43-
.frame(width: 40, height: 40)
44-
.foregroundColor(Color("TextColor"))
45-
}
46-
.clipShape(Circle())
75+
CloseButton(action: { isPresented = false })
4776
}
4877

49-
ForEach(InfoText.content) { text in
50-
HeaderTextPairView(header: text.header, text: text.text)
51-
.padding([.horizontal], 12)
52-
}
78+
InfoContent()
5379
}
5480
.padding([.bottom], 24)
5581
}
82+
#endif
5683
}
5784
}
5885

5986
#Preview("InfoView") {
6087
InfoView(isPresented: .constant(true))
61-
}
88+
}

OLMoE.swift/Views/ModelDownloadView.swift

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ struct Ai2Logo: View {
204204
/// A view that displays the model download progress and status.
205205
struct ModelDownloadView: View {
206206
@StateObject private var downloadManager = BackgroundDownloadManager.shared
207+
@State private var showDownloadConfirmation = false
207208

208209
public var body: some View {
209210
ZStack {
@@ -248,8 +249,42 @@ struct ModelDownloadView: View {
248249
Spacer()
249250
.frame(height: 16)
250251

251-
Button("Download Model", action: downloadManager.startDownload)
252-
.buttonStyle(.PrimaryButton)
252+
Button("Download Model") {
253+
showDownloadConfirmation = true
254+
}
255+
.buttonStyle(.PrimaryButton)
256+
.sheet(isPresented: $showDownloadConfirmation) {
257+
SheetWrapper {
258+
HStack {
259+
Spacer()
260+
CloseButton(action: { showDownloadConfirmation = false })
261+
}
262+
Spacer()
263+
VStack(spacing: 20) {
264+
Text("Download Model")
265+
.font(.title())
266+
267+
Text("The model requires 4.21GB of storage space. Would you like to proceed with the download?")
268+
.multilineTextAlignment(.center)
269+
.font(.body())
270+
271+
VStack(spacing: 12) {
272+
Button {
273+
showDownloadConfirmation = false
274+
downloadManager.startDownload()
275+
} label: {
276+
HStack {
277+
Image(systemName: "arrow.down.circle.fill")
278+
Text("Start Download")
279+
}
280+
}
281+
.buttonStyle(.PrimaryButton)
282+
}
283+
}
284+
.padding()
285+
Spacer()
286+
}
287+
}
253288
}
254289

255290
if let error = downloadManager.downloadError {

OLMoE.swift/Views/UnsupportedDeviceView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct UnsupportedDeviceView: View {
5959
.sheet(isPresented: $showWebView, onDismiss: nil) {
6060
SheetWrapper {
6161
WebViewWithBanner(
62-
url: URL(string: "https://playground.allenai.org/?model=olmoe-0125")!,
62+
url: URL(string: AppConstants.Model.playgroundURL)!,
6363
onDismiss: { showWebView = false }
6464
)
6565
}

0 commit comments

Comments
 (0)