The AI Art Generator App is an Android application that leverages the Stable Diffusion API to create unique artworks based on user-provided prompts. It follows the Clean Architectuer pattern and uses Retrofit for API communication, flows for API states and Glide for efficient image loading.
- Android Studio with Kotlin support
- Knowledge of MVVM architecture
- Retrofit and Glide dependencies added to your project
- Knowledge of Kotlin Flows
- Knowledge of Dagger-Hilt
-
Clone the repository:
git clone https://github.com/UmairOye/AI-Art-Generator.git cd AI-Art-Generator
-
Open the project in Android Studio.
-
Build and run the app on an emulator or physical device.
@Module
@InstallIn(SingletonComponent::class)
object RetrofitInjection {
@Provides
@Singleton
fun provideRetrofitClient(): Retrofit {
return Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
@Provides
@Singleton
fun provideApiService(retrofit: Retrofit): ApiService {
return retrofit.create(ApiService::class.java)
}
}
interface ApiService {
@POST(BuildConfig.END_POINT)
fun makeApiRequest(@Body requestBody: DreamBoothRequest): Call<DreamBoothResponse>
}
override fun makeApiRequest(requestBody: DreamBoothRequest): Flow<RequestState<MetaData?>> =
flow {
emit(RequestState.Loading)
try {
val response = suspendCoroutine { continuation ->
artApi.makeApiRequest(requestBody)
.enqueue(object : Callback<DreamBoothResponse> {
override fun onResponse(
call: Call<DreamBoothResponse>,
response: Response<DreamBoothResponse>
) {
continuation.resume(response)
}
override fun onFailure(call: Call<DreamBoothResponse>, t: Throwable) {
continuation.resumeWithException(t)
}
})
}
if (response.isSuccessful && response.body() != null) {
emit(RequestState.Success(response.body()!!.meta))
Log.d(TAG, "onResponse: ${response.body()?.meta}")
} else {
emit(RequestState.Error(Exception("Response not successful")))
Log.d(TAG, "onResponse: not successful")
}
} catch (e: Exception) {
emit(RequestState.Error(e))
Log.d(TAG, "onFailure: ${e.message}")
}
}.flowOn(Dispatchers.IO)
Glide is used for efficient image loading. Here's an example of how to load an image into an ImageView:
Glide.with(this)
.load("https://example.com/image.jpg")
.into(imageView)
Need help with Android development?
I specialize in:
- Custom UI components (e.g., animated bottom navigation)
- API integration (AI tools, social media, ads)
- Performance optimization and clean architecture
If you found this project useful or had fun exploring it, please consider giving it a star. It's a great way to show your appreciation and it puts a smile on my face! 😊🌟