Skip to content

Commit 6761224

Browse files
committed
Added example for video from local image
1 parent 1864283 commit 6761224

File tree

3 files changed

+51
-19
lines changed

3 files changed

+51
-19
lines changed

Runvey/Runvey.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@
274274
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
275275
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
276276
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
277-
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
277+
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
278278
LD_RUNPATH_SEARCH_PATHS = (
279279
"$(inherited)",
280280
"@executable_path/Frameworks",
@@ -304,7 +304,7 @@
304304
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
305305
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
306306
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
307-
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
307+
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
308308
LD_RUNPATH_SEARCH_PATHS = (
309309
"$(inherited)",
310310
"@executable_path/Frameworks",

Runvey/Runvey.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runvey/Runvey/ContentView.swift

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,48 @@ struct ContentView: View {
1515
@State private var generatedVideoURL: URL?
1616
@State private var isLoading = false
1717
@State private var errorMessage: String?
18+
@State private var imageSelection: PhotosPickerItem?
1819

1920
var body: some View {
2021
NavigationStack {
2122
VStack {
22-
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
23-
if let image = phase.image {
24-
image
25-
.resizable()
26-
.scaledToFit()
27-
.cornerRadius(16)
28-
} else if phase.error != nil {
29-
Image(systemName: "exclamationmark.triangle")
30-
.resizable()
31-
.scaledToFit()
32-
.foregroundColor(.red)
33-
} else {
34-
ProgressView()
23+
if let selectedImage = selectedImage {
24+
Image(uiImage: selectedImage)
25+
.resizable()
26+
.scaledToFit()
27+
.cornerRadius(16)
28+
} else {
29+
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
30+
if let image = phase.image {
31+
image
32+
.resizable()
33+
.scaledToFit()
34+
.cornerRadius(16)
35+
} else if phase.error != nil {
36+
Image(systemName: "exclamationmark.triangle")
37+
.resizable()
38+
.scaledToFit()
39+
.foregroundColor(.red)
40+
} else {
41+
ProgressView()
42+
}
43+
}
44+
}
45+
46+
PhotosPicker(selection: $imageSelection, matching: .images) {
47+
Text("Select Image")
48+
.frame(maxWidth: .infinity)
49+
}
50+
.buttonStyle(.bordered)
51+
.onChange(of: imageSelection) { _, newValue in
52+
Task {
53+
if let data = try? await newValue?.loadTransferable(type: Data.self) {
54+
if let uiImage = UIImage(data: data) {
55+
await MainActor.run {
56+
selectedImage = uiImage
57+
}
58+
}
59+
}
3560
}
3661
}
3762

@@ -72,18 +97,25 @@ struct ContentView: View {
7297

7398
print("DEBUG: Starting video generation")
7499

75-
// Use a random image URL and a prompt text
76-
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"
77100
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."
78101

79102
do {
80103
guard let apiKey = ProcessInfo.processInfo.environment["RUNWAYML_API_KEY"] else {
81104
debugPrint("Warning: RUNWAYML_API_KEY not found in environment variables")
105+
self.errorMessage = "Error: RUNWAYML_API_KEY not found in environment variables"
106+
self.isLoading = false
82107
return
83108
}
84109

85110
let runveyKit = RunveyKit(apiKey: apiKey)
86-
let taskID = try await runveyKit.generateImage(prompt: promptText, imageURL: URL(string: imageURL)!)
111+
let taskID: String
112+
113+
if let selectedImage = selectedImage {
114+
taskID = try await runveyKit.generateImage(prompt: promptText, image: selectedImage)
115+
} else {
116+
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"
117+
taskID = try await runveyKit.generateImage(prompt: promptText, imageURL: URL(string: imageURL)!)
118+
}
87119

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

0 commit comments

Comments
 (0)