Skip to content

Commit

Permalink
Added example for video from local image
Browse files Browse the repository at this point in the history
  • Loading branch information
rudrankriyam committed Oct 7, 2024
1 parent 1864283 commit 6761224
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Runvey/Runvey.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -304,7 +304,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"location" : "https://github.com/rryam/RunveyKit",
"state" : {
"branch" : "main",
"revision" : "3e8a01484eb81404207527eead43a01d4fcb1541"
"revision" : "18642837f11bdfde22e5f1bd50c4480e58969869"
}
}
],
Expand Down
64 changes: 48 additions & 16 deletions Runvey/Runvey/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,48 @@ struct ContentView: View {
@State private var generatedVideoURL: URL?
@State private var isLoading = false
@State private var errorMessage: String?
@State private var imageSelection: PhotosPickerItem?

var body: some View {
NavigationStack {
VStack {
AsyncImage(url: URL(string: "https://images.unsplash.com/photo-1542051841857-5f90071e7989?q=80&w=3270&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wAWdlfHx8fGVufDB8fHx8fA%3D%3D")) { phase in
if let image = phase.image {
image
.resizable()
.scaledToFit()
.cornerRadius(16)
} else if phase.error != nil {
Image(systemName: "exclamationmark.triangle")
.resizable()
.scaledToFit()
.foregroundColor(.red)
} else {
ProgressView()
if let selectedImage = selectedImage {
Image(uiImage: selectedImage)
.resizable()
.scaledToFit()
.cornerRadius(16)
} else {
AsyncImage(url: URL(string: "https://images.unsplash.com/photo-1542051841857-5f90071e7989?q=80&w=3270&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wAWdlfHx8fGVufDB8fHx8fA%3D%3D")) { phase in
if let image = phase.image {
image
.resizable()
.scaledToFit()
.cornerRadius(16)
} else if phase.error != nil {
Image(systemName: "exclamationmark.triangle")
.resizable()
.scaledToFit()
.foregroundColor(.red)
} else {
ProgressView()
}
}
}

PhotosPicker(selection: $imageSelection, matching: .images) {
Text("Select Image")
.frame(maxWidth: .infinity)
}
.buttonStyle(.bordered)
.onChange(of: imageSelection) { _, newValue in
Task {
if let data = try? await newValue?.loadTransferable(type: Data.self) {
if let uiImage = UIImage(data: data) {
await MainActor.run {
selectedImage = uiImage
}
}
}
}
}

Expand Down Expand Up @@ -72,18 +97,25 @@ struct ContentView: View {

print("DEBUG: Starting video generation")

// Use a random image URL and a prompt text
let imageURL = "https://images.unsplash.com/photo-1542051841857-5f90071e7989?q=80&w=3270&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wAWdlfHx8fGVufDB8fHx8fA%3D%3D"
let promptText = "Dynamic tracking shot: The camera glides through the iconic Shibuya Crossing in Tokyo at night, capturing the bustling intersection bathed in vibrant neon lights. Countless pedestrians cross the wide intersection as towering digital billboards illuminate the scene with colorful advertisements. The wet pavement reflects the dazzling lights, creating a cinematic urban atmosphere."

do {
guard let apiKey = ProcessInfo.processInfo.environment["RUNWAYML_API_KEY"] else {
debugPrint("Warning: RUNWAYML_API_KEY not found in environment variables")
self.errorMessage = "Error: RUNWAYML_API_KEY not found in environment variables"
self.isLoading = false
return
}

let runveyKit = RunveyKit(apiKey: apiKey)
let taskID = try await runveyKit.generateImage(prompt: promptText, imageURL: URL(string: imageURL)!)
let taskID: String

if let selectedImage = selectedImage {
taskID = try await runveyKit.generateImage(prompt: promptText, image: selectedImage)
} else {
let imageURL = "https://images.unsplash.com/photo-1542051841857-5f90071e7989?q=80&w=3270&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wAWdlfHx8fGVufDB8fHx8fA%3D%3D"
taskID = try await runveyKit.generateImage(prompt: promptText, imageURL: URL(string: imageURL)!)
}

debugPrint("DEBUG: Successfully created task, ID: \(taskID)")

Expand Down

0 comments on commit 6761224

Please sign in to comment.