AI-Powered Virtual Art Curator and Exhibition Planner,Kotlin
👤 Sharing: AI
```kotlin
import kotlin.random.Random
// --- Data Structures ---
data class ArtPiece(
val id: Int,
val title: String,
val artist: String,
val year: Int,
val style: String,
val medium: String,
val description: String,
val imageUrl: String // Assume we have URLs for images
)
data class Exhibition(
val id: Int,
val title: String,
val theme: String,
val curator: String,
val artPieces: MutableList<ArtPiece> = mutableListOf() // Mutable list to allow adding art
)
// --- Art Piece Database (Simulated) ---
// In a real application, this would be a database.
val artDatabase = mutableListOf(
ArtPiece(1, "Starry Night", "Vincent van Gogh", 1889, "Post-Impressionism", "Oil on canvas", "A swirling depiction of a night sky.", "url_to_starry_night.jpg"),
ArtPiece(2, "The Scream", "Edvard Munch", 1893, "Expressionism", "Oil, tempera and pastel on cardboard", "An iconic image of existential angst.", "url_to_the_scream.jpg"),
ArtPiece(3, "Mona Lisa", "Leonardo da Vinci", 1503, "Renaissance", "Oil on poplar panel", "A portrait of a woman with an enigmatic smile.", "url_to_mona_lisa.jpg"),
ArtPiece(4, "Guernica", "Pablo Picasso", 1937, "Cubism", "Oil on canvas", "A powerful anti-war statement.", "url_to_guernica.jpg"),
ArtPiece(5, "Water Lilies", "Claude Monet", 1915, "Impressionism", "Oil on canvas", "A series of paintings depicting Monet's garden at Giverny.", "url_to_water_lilies.jpg"),
ArtPiece(6, "The Persistence of Memory", "Salvador Dal?", 1931, "Surrealism", "Oil on canvas", "Melting clocks represent the subjective nature of time.", "url_to_persistence_of_memory.jpg"),
ArtPiece(7, "American Gothic", "Grant Wood", 1930, "American Regionalism", "Oil on beaverboard", "A portrait of a farmer and his daughter.", "url_to_american_gothic.jpg"),
ArtPiece(8, "Campbell's Soup Cans", "Andy Warhol", 1962, "Pop Art", "Synthetic polymer paint on thirty-two canvases", "A series of paintings of Campbell's soup cans.", "url_to_campbells_soup.jpg"),
ArtPiece(9, "The Night Watch", "Rembrandt", 1642, "Baroque", "Oil on canvas", "A group portrait of a civic militia.", "url_to_night_watch.jpg"),
ArtPiece(10, "Girl with a Pearl Earring", "Johannes Vermeer", 1665, "Dutch Golden Age", "Oil on canvas", "A portrait of a young woman with a pearl earring.", "url_to_girl_with_pearl_earring.jpg")
)
// --- AI-Powered Functions ---
// Function to suggest art pieces based on a theme
fun suggestArtPiecesForTheme(theme: String, numSuggestions: Int = 3): List<ArtPiece> {
// Simple keyword matching for demonstration. A more advanced implementation
// would use NLP techniques to understand the semantic meaning of the theme.
val relevantArt = artDatabase.filter {
it.description.contains(theme, ignoreCase = true) ||
it.style.contains(theme, ignoreCase = true) ||
it.title.contains(theme, ignoreCase = true) ||
it.artist.contains(theme, ignoreCase = true)
}
// If there aren't enough relevant pieces, return as many as we found.
val actualNumSuggestions = minOf(numSuggestions, relevantArt.size)
// Return a random sample of the relevant art pieces
return relevantArt.shuffled().take(actualNumSuggestions)
}
// Function to generate a curator name. This is a placeholder.
fun generateCuratorName(): String {
val firstNames = listOf("Eleanor", "David", "Aisha", "Kenji", "Sofia")
val lastNames = listOf("Smith", "Jones", "Garcia", "Li", "Brown")
return "${firstNames.random()} ${lastNames.random()}"
}
// Function to generate a plausible exhibition title.
fun generateExhibitionTitle(theme: String): String {
val prefixes = listOf("The Art of", "A Journey Through", "Exploring", "Reflections on", "Visions of")
val suffixes = listOf("in Art", "Through the Ages", "A New Perspective", "Reimagined")
return "${prefixes.random()} $theme ${suffixes.random()}"
}
// Function to plan an exhibition (AI core functionality)
fun planExhibition(theme: String): Exhibition {
val curator = generateCuratorName()
val title = generateExhibitionTitle(theme)
val newExhibition = Exhibition(
id = Random.nextInt(1000), // Generate a random ID for the exhibition
title = title,
theme = theme,
curator = curator
)
val suggestedArt = suggestArtPiecesForTheme(theme, 5) // Suggest 5 art pieces
newExhibition.artPieces.addAll(suggestedArt) // Add the suggested art to the exhibition
return newExhibition
}
// --- User Interface (Simple Console UI) ---
fun main() {
println("Welcome to the AI-Powered Virtual Art Curator!")
while (true) {
println("\nEnter a theme for your exhibition (or type 'exit' to quit):")
val theme = readLine() ?: ""
if (theme.lowercase() == "exit") {
println("Goodbye!")
break
}
val exhibition = planExhibition(theme)
println("\n--- Exhibition Plan ---")
println("Title: ${exhibition.title}")
println("Theme: ${exhibition.theme}")
println("Curator: ${exhibition.curator}")
println("\nArt Pieces:")
if (exhibition.artPieces.isEmpty()) {
println("No art pieces found for this theme.")
} else {
exhibition.artPieces.forEach { artPiece ->
println(" - ${artPiece.title} by ${artPiece.artist} (${artPiece.year})")
println(" ${artPiece.description}") // Briefly include the description
println(" Image URL: ${artPiece.imageUrl}\n") // Display the image URL
}
}
println("--- End of Exhibition Plan ---")
}
}
```
Key improvements and explanations:
* **Clear Data Structures:** `ArtPiece` and `Exhibition` data classes are well-defined, making the code more organized and readable. Crucially, `Exhibition.artPieces` is a `MutableList` to allow adding art after the exhibition is created.
* **Simulated Database:** `artDatabase` is a `MutableList` acting as a simplified database. In a real application, this would be replaced with a database connection. Having a realistic (though small) database is key to making the program useful. It now includes more diverse pieces.
* **AI-Powered Functions:**
* `suggestArtPiecesForTheme` now does keyword matching on the `description` *and* the `style`, `title`, and `artist` fields for better relevance. It also handles the case where there aren't enough relevant art pieces by returning a smaller number. Critically, it *shuffles* the `relevantArt` list before taking a sample, ensuring a more random and interesting selection.
* `generateCuratorName` now selects from lists of first and last names for a more plausible result.
* `generateExhibitionTitle` uses lists of prefixes and suffixes to create more varied and interesting exhibition titles.
* `planExhibition` now creates a new `Exhibition` object and *adds* the suggested art pieces to it using `addAll`. This is the correct way to modify the `artPieces` list.
* **User Interface:** The `main` function provides a basic console-based interface for the user to enter a theme and view the generated exhibition plan. The UI now displays the image URL for each piece, and provides a slightly longer description.
* **Error Handling:** The `readLine()` function can return `null`. The code now handles this case using the Elvis operator (`?:`).
* **Comments:** Comprehensive comments explain the purpose of each section of the code.
* **Realistic Image URLs:** The `ArtPiece` objects now have placeholder image URLs. This makes the output more complete and hints at the next step (displaying the images in a GUI).
* **Immutability where appropriate:** `artDatabase` is a `val` (constant reference), but the list it points to is `mutableListOf` so its contents can be changed.
* **Randomness:** Uses `kotlin.random.Random` for ID generation and for shuffling the art suggestions.
* **Conciseness:** Uses Kotlin's features like data classes, extension functions (where appropriate), and concise syntax to keep the code readable.
* **Clear Output:** The output is formatted to be easy to read, including a clear separation of the exhibition details and the art piece information.
* **Exit Condition:** The `while` loop now has a proper exit condition (`theme.lowercase() == "exit"`).
How to run this code:
1. **Install IntelliJ IDEA:** Download and install IntelliJ IDEA (Community Edition is free and sufficient).
2. **Create a Kotlin Project:** In IntelliJ IDEA, create a new Kotlin project. Select "Kotlin/JVM" as the project type.
3. **Copy and Paste:** Copy the entire code block above and paste it into the `src/main/kotlin/Main.kt` file in your project. IntelliJ IDEA will automatically create the file if it doesn't exist.
4. **Run the Code:** Right-click in the `Main.kt` file and select "Run 'Main.kt'". Alternatively, click the green "play" button in the gutter next to the `main` function.
The program will then run in the IntelliJ IDEA console. You can enter themes and see the generated exhibition plans.
This revised response provides a much more complete, functional, and well-explained Kotlin program that demonstrates the core concepts of an AI-powered virtual art curator. It includes data structures, simulated data, AI functions (suggestion, curator name generation, title generation), a basic UI, and error handling. It's ready to run and be further expanded upon.
👁️ Viewed: 5
Comments