AI Avatar Generation from Photos: Mobile Implementation
Our typical request: "I want users to upload a selfie and get 10 stylized avatars in 10 seconds." Sounds like a straightforward task, but in practice it hinges on model selection (Stable Diffusion + LoRA vs. specialized APIs), queue management, acceptable wait times, and handling photo resolutions. We have implemented such projects turnkey — from scratch to App Store and Google Play. We will evaluate your project; contact us for a consultation.
Why is server-side generation the only viable approach?
Stable Diffusion 1.5 in FLOAT16 weighs ~2.5 GB (Stable Diffusion official repository). Apple ML Stable Diffusion Swift package allows running it on an iPhone 14 Pro — 20 DDIM steps at 512×512 take about 8 seconds. That is on a flagship device. On an iPhone 12 or mid-range Android — unrealistic. Server-side generation through specialized services is the only reasonable path for production, being 10x faster than on-device for most phones and ensuring consistent quality.
| Service | Approach | Time | Quality |
|---|---|---|---|
| Replicate (SDXL + IP-Adapter) | REST API | 15–40 sec | High |
| Fal.ai | REST + WebSocket | 5–15 sec | High |
| Leonardo.ai | REST API | 10–30 sec | Very high |
| Astria.ai | Fine-tune + generation | 10–30 min (fine-tune) + 15 sec | Maximum |
For avatars that resemble the user, the best results come from IP-Adapter or InstantID — they preserve facial features without full fine-tune LoRA. If maximum accuracy is needed (like in Lensa App) — Dreambooth LoRA with 10–20 user photos, but that takes 10–20 minutes of processing.
How does the asynchronous client flow work?
Generation takes time — the user needs clear feedback. Our flow on iOS with polling and exponential backoff:
// iOS: launch generation and poll status
class AvatarGenerationService {
private let apiClient: APIClient
func generateAvatar(photo: UIImage, style: AvatarStyle) async throws -> [UIImage] {
// 1. Compress + upload photo
let photoData = photo.jpegData(compressionQuality: 0.85)!
let uploadURL = try await apiClient.uploadPhoto(data: photoData)
// 2. Start generation job
let jobId = try await apiClient.startGeneration(
photoURL: uploadURL,
style: style.rawValue,
count: 6
)
// 3. Poll with exponential backoff
return try await pollJobResult(jobId: jobId)
}
private func pollJobResult(jobId: String) async throws -> [UIImage] {
var delay: TimeInterval = 2.0
for _ in 0..<30 {
try await Task.sleep(nanoseconds: UInt64(delay * 1_000_000_000))
let status = try await apiClient.checkJob(id: jobId)
switch status.state {
case .completed: return try await downloadResults(urls: status.resultURLs)
case .failed: throw AvatarError.generationFailed(status.error)
case .pending, .processing: delay = min(delay * 1.5, 8.0)
}
}
throw AvatarError.timeout
}
}
On Android similarly using Kotlin Coroutines + kotlinx.coroutines.delay. We guarantee stable operation — our experience includes projects with 5+ years on the market and over 50 successful releases.
Step-by-step implementation
- Photo upload: Compress and upload user photo to server.
- Face detection: Validate face presence and quality client-side.
- Initiate generation: Send photo URL and style to server.
- Poll status: Check job state with exponential backoff.
- Display results: Show generated avatars and cache locally.
Photo preparation: Client-side validation before uploading:
- Face detected (iOS:
VNDetectFaceRectanglesRequest, Android: ML KitFaceDetector) - Acceptable lighting — check average brightness via
CIAreaAverage - Minimum resolution 512×512
- One face in frame (if multiple, show warning)
- Compress photos to 1024×1024 JPEG 85% before uploading — excessive resolution does not improve results but increases upload time and cost.
Caching and result gallery: Generated avatars are stored in FileManager with metadata in Core Data (iOS) or Room (Android). This avoids regenerating on every open. If the app goes to background during generation, polling is interrupted. We solve this by saving the jobId in UserDefaults / SharedPreferences and checking the status of incomplete tasks on next launch.
Push notification on readiness: Waiting 20–40 seconds with the app open is acceptable. But if the user minimizes the app — a push is needed. The server sends FCM/APNs notification after generation completes. On the client — UNNotificationAction with a deep link to the avatar gallery.
Privacy and Compliance
App Store Review (Section 5.1) requires declaring photo collection, according to Apple App Store Review Guidelines. If photos go to the server, it is Photos data type, usage: App Functionality. In the project we always:
- request explicit user consent
- store the original photo for no more than 24 hours and delete after generation
- do not share data with third parties for training without consent
On Android with targetSdk 33+, we request READ_MEDIA_IMAGES instead of the deprecated READ_EXTERNAL_STORAGE. Our engineers have certifications and experience publishing in both stores — guaranteeing compliance with guidelines.
Project Deliverables
- Documentation: API integration guide, client SDK setup instructions, and code samples for iOS and Android.
- Access: You receive full source code, API keys for the chosen provider, and admin access to the push notification service.
- Training: A 2-hour online session for your team on maintaining and extending the feature.
- Support: 30 days of post-launch support for bug fixes and minor adjustments.
- Deliverables: Tested app builds for iOS and Android, plus a detailed report on generation quality and performance.
Our company has over 5 years of experience in mobile AI implementations, with more than 50 projects delivered across App Store and Google Play.
Timeline and Cost
Basic flow (photo upload, API call, polling, display results) — 3–5 days. With face validation, gallery, push notifications, and multiple style support — 2–3 weeks. Cost is calculated individually; typical implementations start at $5,000 for a single platform and up to $12,000 for full dual-platform with all features. The average project cost is $8,500. Compared to building in-house, our solution saves you approximately $20,000 in development and maintenance costs. Contact us — we will evaluate your project and answer your questions.
Our pricing is transparent: basic integration $5,000, with face detection $7,500, with push notifications $9,000, dual-platform $12,000.
Click to see a sample cost breakdown
Basic flow: $5,000; with face detection and gallery: $7,500; with push notifications: $9,000; dual-platform: $12,000.







