Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions LexAI_iOS/LexAI_iOS/Managers/ScanDocumentsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ struct ScanDocumentsView: UIViewControllerRepresentable {
@Binding var isPresented: Bool
var onTextAdded: ((String) -> Void)?

//Makes and configures the VNDocumentCameraViewController for document scanning
func makeUIViewController(context: Context) -> VNDocumentCameraViewController {
let scanner = VNDocumentCameraViewController()
scanner.delegate = context.coordinator
return scanner
}

//Updates the view controller when SwiftUI state changes- keeps it currently empty as no updates are needed
func updateUIViewController(
_ uiViewController: VNDocumentCameraViewController,
context: Context
) {}

//Makes a coordinator to handle delegate methods from the document camera view controller
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
Expand All @@ -39,6 +42,7 @@ struct ScanDocumentsView: UIViewControllerRepresentable {
self.parent = parent
}

//Processes the scanned document pages, extracts text from each page and calls the onTextAdded callback with the combined text
func documentCameraViewController(
_ controller: VNDocumentCameraViewController,
didFinishWith scan: VNDocumentCameraScan
Expand All @@ -61,10 +65,12 @@ struct ScanDocumentsView: UIViewControllerRepresentable {
parent.isPresented = false
}

//Handles cancellation of the document scanner by dismissing the view
func documentCameraViewControllerDidCancel(_ controller: VNDocumentCameraViewController) {
parent.isPresented = false
}

//Handles errors during document scanning by logging the error and dismissing the view
func documentCameraViewController(
_ controller: VNDocumentCameraViewController,
didFailWithError error: Error
Expand All @@ -73,6 +79,7 @@ struct ScanDocumentsView: UIViewControllerRepresentable {
parent.isPresented = false
}

//Extracts text from a given UIImage using Vision's text recognition
private func extractText(from image: UIImage) -> String? {
guard let cgImage = image.cgImage else { return nil }

Expand All @@ -98,6 +105,7 @@ struct ScanDocumentsView: UIViewControllerRepresentable {
struct ScanDocumentsPreviewWrapper: View {
@State private var showScanner = true

//Gives a preview of the document scanner view for SwiftUI previews
var body: some View {
Text("Document Scanner Preview")
.font(.title2)
Expand Down
9 changes: 9 additions & 0 deletions LexAI_iOS/LexAI_iOS/Views/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct ChatView: View {

private let functions = Functions.functions()

//Defines the main chat interface layout, including the title, message list, and input bar.
var body: some View {
ZStack(alignment: .bottom) {
VStack(spacing: 0) {
Expand Down Expand Up @@ -150,6 +151,7 @@ struct ChatView: View {
.buttonStyle(.plain)
}

//Makes a scrollable list of chat messages with automatic scrolling to the bottom
// MARK: Message List

private var messageList: some View {
Expand All @@ -176,6 +178,7 @@ struct ChatView: View {
.frame(maxWidth: .infinity, maxHeight: .infinity)
}

//Makes the input bar with scan document button, text field, and send button
// MARK: Input Bar

private var inputBar: some View {
Expand Down Expand Up @@ -220,6 +223,7 @@ struct ChatView: View {
.padding(.top)
}

//Sends the user's message, validates input, and handles the AI response asynchronously
// MARK: File Import Handler

private func handleFileImport(_ result: Result<[URL], Error>) {
Expand Down Expand Up @@ -282,8 +286,11 @@ struct ChatView: View {
}
}

//Calls the Firebase function to generate an AI response based on the prompt and chat history
private func generateAnswer(prompt: String, targetLanguage: String) async throws -> String {
let callable = functions.httpsCallable("chat")

//Build chat history from previous messages (exclude the one we just added)
let chatHistory: [[String: String]] = messages.dropLast().map { msg in
["role": msg.isFromUser ? "user" : "assistant", "content": msg.text]
}
Expand All @@ -307,6 +314,8 @@ struct ChatView: View {

private struct MessageBubbleView: View {
let message: ChatMessage

//Defines the layout for displaying a single chat message bubble

var body: some View {
HStack(alignment: .top) {
Expand Down
1 change: 1 addition & 0 deletions LexAI_iOS/LexAI_iOS/Views/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct HomeView: View {
@StateObject private var sidebarVM = SidebarViewModel()
private let languages = ["English", "Spanish", "French", "Arabic", "German"]

//Defines the main view layout, including the chat view, sidebar, and language dropdown
var body: some View {
NavigationStack {
GeometryReader { geo in
Expand Down
10 changes: 5 additions & 5 deletions installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ Supported MacOS Versions:
- macOS 15 (Sequoia)

Pre-installations:
Step 1: Xcode
Step 2: node.js | https://nodejs.org/en/
Step 3: Git | https://git-scm.com/downloads
Step 4: Python 3.9+ | python.org/downloads
Step 5: Request to be added as a FireBase project member and download the GoogleService-Info.plist
1.) Xcode
2.) node.js | https://nodejs.org/en/
3.) Git | https://git-scm.com/downloads
4.) Python 3.9+ | python.org/downloads
5.) Request to be added as a FireBase project member and download the GoogleService-Info.plist

Instructions to build and Install the Software
Step 1: Verify you have all prerequisite and pre-installations to build the project.
Expand Down
Loading