Skip to content

Commit

Permalink
Merge branch 'release-20241118' of github.com:allenai/OLMoE.swift int…
Browse files Browse the repository at this point in the history
…o separate-lambda
  • Loading branch information
Stanley-Jovel committed Nov 19, 2024
2 parents b2136e1 + f9287bd commit 4260c0c
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 107 deletions.
5 changes: 5 additions & 0 deletions OLMoE-swift-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
<string>$(API_URL)</string>
<key>APP_ATTEST_TEMP_CHALLENGE</key>
<string>$(APP_ATTEST_TEMP_CHALLENGE)</string>
<key>UIAppFonts</key>
<array>
<string>Manrope-VariableFont_wght.ttf</string>
<string>pp-telegraf.ttf</string>
</array>
</dict>
</plist>
38 changes: 38 additions & 0 deletions OLMoE.swift/Assets.xcassets/Surface.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x57",
"green" : "0x52",
"red" : "0x10"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x57",
"green" : "0x52",
"red" : "0x10"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
4 changes: 3 additions & 1 deletion OLMoE.swift/OLMoE_swiftApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ struct OLMoE_swiftApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.font(.manrope())
.environment(\.font, .manrope())
.environment(\.colorScheme, .dark)

}
}
}
Expand Down
15 changes: 15 additions & 0 deletions OLMoE.swift/Resources/TelegrafFont.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// TelegrafFont.swift
// OLMoE.swift
//
// Created by Stanley Jovel on 11/18/24.
//

import SwiftUI

extension Font {
static func telegraf(_ weight: Weight = .regular, textStyle: TextStyle = .body) -> Font {
custom("PPTelegraf-Regular", size: UIFont.preferredFont(forTextStyle: textStyle.uiTextStyle).pointSize)
.weight(weight)
}
}
Binary file added OLMoE.swift/Resources/pp-telegraf.ttf
Binary file not shown.
219 changes: 117 additions & 102 deletions OLMoE.swift/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,65 @@ struct BotView: View {
}
}
}


@ViewBuilder
func shareButton() -> some View {
Button(action: {
isTextEditorFocused = false
isSharingConfirmationVisible = true
}) {
HStack {
if isSharing {
SpinnerView(color: Color("AccentColor"))
} else {
Image(systemName: "square.and.arrow.up")
}
}
.foregroundColor(Color("TextColor"))
}
.popover(isPresented: $isSharingConfirmationVisible, content: {
DisclaimerPage(
title: Disclaimers.ShareDisclaimer().title,
message: Disclaimers.ShareDisclaimer().text,
confirm: DisclaimerPage.PageButton(
text: Disclaimers.ShareDisclaimer().buttonText,
onTap: {
shareConversation()
isSharingConfirmationVisible = false
}
),
cancel: DisclaimerPage.PageButton(
text: "Cancel",
onTap: {
isSharingConfirmationVisible = false
}
)
)
.presentationBackground(Color("BackgroundColor"))
})
.disabled(isSharing || bot.history.isEmpty)
.opacity(isSharing || bot.history.isEmpty ? 0.5 : 1)
}

@ViewBuilder
func trashButton() -> some View {
return Button(action: {
isTextEditorFocused = false
isDeleteHistoryConfirmationVisible = true
stop()
}) {
Image(systemName: "trash.fill")
.foregroundColor(Color("TextColor"))
}.alert("Delete history?", isPresented: $isDeleteHistoryConfirmationVisible, actions: {
Button("Delete", action: deleteHistory)
Button("Cancel", role: .cancel) {
isDeleteHistoryConfirmationVisible = false
}
})
.disabled(isDeleteButtonDisabled)
.opacity(isDeleteButtonDisabled ? 0.5 : 1)
}

var body: some View {
GeometryReader { geometry in
contentView(in: geometry)
Expand Down Expand Up @@ -270,7 +328,6 @@ struct BotView: View {
.foregroundColor(Color("TextColor"))
.id("bottomID") // Unique ID for scrolling
Color.clear.frame(height: 1).id("bottomID2")

}
}
.onChange(of: bot.output) { _ in
Expand Down Expand Up @@ -320,12 +377,10 @@ struct BotView: View {
.scrollContentBackground(.hidden)
.background(
RoundedRectangle(cornerRadius: 8)
.fill(Color("Surface"))
.foregroundStyle(.thinMaterial)
)
.overlay(
RoundedRectangle(cornerRadius: 8)
.stroke(Color("TextColor").opacity(0.2), lineWidth: 1)
)
.clipShape(RoundedRectangle(cornerRadius: 8))
.foregroundColor(Color("TextColor"))
.font(.manrope())
.focused($isTextEditorFocused)
Expand All @@ -348,42 +403,6 @@ struct BotView: View {
}
}
VStack(spacing: 8) {
Button(action: {
isTextEditorFocused = false
isSharingConfirmationVisible = true
}) {
HStack {
if isSharing {
SpinnerView(color: Color("AccentColor"))
} else {
Image(systemName: "square.and.arrow.up")
}
}
.foregroundColor(Color("TextColor"))
.font(.system(size: 24))
.frame(width: 40, height: 40)
}
.popover(isPresented: $isSharingConfirmationVisible, content: {
DisclaimerPage(
title: Disclaimers.ShareDisclaimer().title,
message: Disclaimers.ShareDisclaimer().text,
confirm: DisclaimerPage.PageButton(
text: Disclaimers.ShareDisclaimer().buttonText,
onTap: {
shareConversation()
isSharingConfirmationVisible = false
}
),
cancel: DisclaimerPage.PageButton(
text: "Cancel",
onTap: {
isSharingConfirmationVisible = false
}
)
)
.presentationBackground(Color("BackgroundColor"))
})
.disabled(isSharing || bot.history.isEmpty)
ZStack {
if isGenerating {
Button(action: stop) {
Expand All @@ -402,24 +421,6 @@ struct BotView: View {
}
.font(.system(size: 24))
.frame(width: 40, height: 40)

Button(action: {
isTextEditorFocused = false
isDeleteHistoryConfirmationVisible = true
stop()
}) {
Image(systemName: "trash.fill")
.foregroundColor(Color("TextColor"))
.font(.system(size: 24))
.frame(width: 40, height: 40)
}.alert("Delete history?", isPresented: $isDeleteHistoryConfirmationVisible, actions: {
Button("Delete", action: deleteHistory)
Button("Cancel", role: .cancel) {
isDeleteHistoryConfirmationVisible = false
}
})
.disabled(isDeleteButtonDisabled)
.opacity(isDeleteButtonDisabled ? 0.5 : 1)
}
}
.padding(.horizontal)
Expand All @@ -435,6 +436,13 @@ struct BotView: View {
.gesture(TapGesture().onEnded({
isTextEditorFocused = false
}))
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItemGroup(placement: .navigationBarTrailing) {
shareButton()
trashButton()
}
}
}
}

Expand All @@ -459,6 +467,7 @@ struct ActivityViewController: UIViewControllerRepresentable {
func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext<ActivityViewController>) {}
}


struct ContentView: View {
@StateObject private var downloadManager = BackgroundDownloadManager.shared
@State private var bot: Bot?
Expand All @@ -475,51 +484,57 @@ struct ContentView: View {
]

var body: some View {
VStack {
if !isSupportedDevice && !useMockedModelResponse {
UnsupportedDeviceView(
proceedAnyway: { isSupportedDevice = true },
proceedMocked: {
bot?.loopBackTestResponse = true
useMockedModelResponse = true
}
NavigationStack {
VStack {
if !isSupportedDevice && !useMockedModelResponse {
UnsupportedDeviceView(
proceedAnyway: { isSupportedDevice = true },
proceedMocked: {
bot?.loopBackTestResponse = true
useMockedModelResponse = true
}
)
} else if let bot = bot {
BotView(bot)
} else {
ModelDownloadView()
}
}
.onChange(of: downloadManager.isModelReady) { newValue in
if newValue && bot == nil {
initializeBot()
}
}
.popover(isPresented: $showDisclaimerPage) {
let page = disclaimers[disclaimerPageIndex]
DisclaimerPage(
title: page.title,
message: page.text,
confirm: DisclaimerPage.PageButton(
text: page.buttonText,
onTap: {
nextDisclaimerPage()
})
)
} else if let bot = bot {
BotView(bot)
} else {
ModelDownloadView()
.interactiveDismissDisabled(true)
.presentationBackground(Color("BackgroundColor"))
}
}
.onChange(of: downloadManager.isModelReady) { newValue in
if newValue && bot == nil {
initializeBot()
.onAppear(perform: checkModelAndInitializeBot)
.onAppear {
if !hasSeenDisclaimer {
showDisclaimerPage = true
}
}
}
.popover(isPresented: $showDisclaimerPage) {
let page = disclaimers[disclaimerPageIndex]
DisclaimerPage(
title: page.title,
message: page.text,
confirm: DisclaimerPage.PageButton(
text: page.buttonText,
onTap: {
nextDisclaimerPage()
})
)
.interactiveDismissDisabled(true)
.presentationBackground(Color("BackgroundColor"))
}
.overlay(
InfoButton(action: { showInfoPage = true })
, alignment: .topTrailing
)
.sheet(isPresented: $showInfoPage) {
InfoView()
}
.onAppear(perform: checkModelAndInitializeBot)
.onAppear {
if !hasSeenDisclaimer {
showDisclaimerPage = true
.navigationBarTitleDisplayMode(.inline)
.toolbar {
AppToolbar(
leadingContent: {
InfoButton(action: { showInfoPage = true })
}
)
}
.sheet(isPresented: $showInfoPage) {
InfoView()
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions OLMoE.swift/Views/InfoPageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ struct InfoButton: View {
var body: some View {
Button(action: action) {
Image(systemName: "info.circle")
.font(.system(size: 24))
.frame(width: 40, height: 40)
.foregroundColor(Color("TextColor"))
.padding()
}
Expand Down
33 changes: 33 additions & 0 deletions OLMoE.swift/Views/Toolbar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// ToolBar.swift
// OLMoE.swift
//
// Created by Thomas Jones on 11/18/24.
//

import SwiftUI

struct AppToolbar<Content: View>: ToolbarContent {

let leadingContent: Content

init(
@ViewBuilder leadingContent: () -> Content = { EmptyView() }
) {
self.leadingContent = leadingContent()
}

var body: some ToolbarContent {
ToolbarItemGroup(placement: .navigationBarLeading) {
self.leadingContent
}

ToolbarItem(placement: .principal) {
Image("Splash")
.resizable()
.scaledToFit()
.frame(width: 60, height: 60) // Adjust size as needed
}
}
}

Loading

0 comments on commit 4260c0c

Please sign in to comment.