Skip to content

alcow5/Lore-Generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“œ Lore Generator

Transform ordinary objects into extraordinary tales with AI-powered mystical lore generation

๐ŸŒŸ Overview

Lore Generator is an iOS app that uses computer vision and AI to create fantasy-style backstories for any object you photograph. Point your camera at everyday items and discover their hidden mystical origins!

โœจ Features

  • ๐Ÿ“ธ Camera Integration: Take photos directly or choose from photo library
  • ๐Ÿ”ฎ AI-Powered Lore: Generate fantasy backstories using LLaVA vision-language model
  • ๐Ÿ“ฑ Beautiful UI: Fantasy-themed interface with scroll and star iconography
  • ๐Ÿ’พ Local Storage: Save and browse your collection of enchanted objects
  • ๐ŸŒ™ Privacy-First: All data stored locally on your device

๐Ÿ—๏ธ Architecture

Frontend (iOS/SwiftUI)

  • SwiftUI interface with modern iOS design patterns
  • Core Data for local storage of lore objects
  • PhotosPicker and UIImagePickerController for image capture
  • Fantasy-themed UI with custom styling and animations

Backend Integration

  • HTTP API communication with local LLaVA server
  • Multipart form uploads for image processing
  • JSON response parsing for lore text
  • Graceful error handling with fallback mock responses

๐Ÿ”„ Backend Workflow

The Lore Generator API is a lightweight proxy service that orchestrates AI-powered lore generation through a multi-step process:

1. ๐Ÿ“ธ Image Upload (Mobile App)

The iOS app sends a multipart/form-data POST request containing a JPEG image to:

http://YOUR_SERVER_IP:3001/generate-lore

2. ๐Ÿ” Image Captioning (LLaVA)

The proxy receives the image and forwards it to a locally hosted LLaVA server:

http://YOUR_SERVER_IP:11434/api/generate
  • Image is converted to base64 format
  • Sent with prompt: "Describe this image in vivid, creative detail."
  • LLaVA responds with a detailed caption

3. โœจ Lore Generation (LLM)

The caption is then processed through a fantasy lore prompt:

"Generate a fantasy item lore based on this description: [caption]"
  • Produces stylized fantasy-style stories and item descriptions
  • Creates mystical backstories for ordinary objects

4. ๐Ÿ“ฑ Response (Back to App)

The final lore is returned to the iOS app as JSON:

{
  "lore": "In the heart of the Elderwood Forest, this ancient artifact..."
}

๐Ÿ› ๏ธ Backend Technologies

  • Backend Framework: FastAPI (Python)
  • Image Captioning: LLaVA (Locally hosted vision-language model)
  • Lore Generation: LLM (Qwen-1.5, LLaMA, or other GGUF-compatible models)
  • Networking: URLSession in Swift with multipart/form-data
  • Image Processing: Base64 encoding for API communication

๐Ÿ› ๏ธ Technical Stack

  • Language: Swift 5.9+
  • Framework: SwiftUI + UIKit bridges
  • Database: Core Data
  • Networking: URLSession with async/await
  • Image Processing: UIImage + JPEG compression
  • Deployment: iOS 16.0+

๐Ÿ“ฑ Key Components

Core Files

  • ContentView.swift - Main interface and navigation
  • LoreService.swift - Network service for API communication
  • ImagePicker.swift - Camera and photo library integration
  • LoreDisplayView.swift - Fantasy-themed lore presentation
  • Persistence.swift - Core Data stack management

Data Model

LoreObject {
    id: UUID
    imageData: Data
    loreText: String
    objectName: String?
    timestamp: Date
}

๐Ÿš€ Getting Started

Prerequisites

  • Xcode 15.0+
  • iOS 16.0+ device or simulator
  • LLaVA server running at specified IP (for real AI generation)

Setup

  1. Clone the repository
  2. Configure Server IP: Replace YOUR_SERVER_IP in these files with your actual server IP:
    • Lore Generator/LoreService.swift (line 12)
    • Lore Generator/Lore-Generator-Info.plist (in NSExceptionDomains)
  3. Open Lore Generator.xcodeproj in Xcode
  4. Configure your target device
  5. Build and run!

Backend Server Setup

For full AI functionality, deploy the complete backend stack:

1. FastAPI Proxy Server

# Deploy FastAPI proxy server at YOUR_SERVER_IP:3001
# Handles image upload and orchestrates AI pipeline

2. LLaVA Vision Model

# Configure LLaVA model endpoint at YOUR_SERVER_IP:11434
# Provides image captioning capabilities

3. Language Model (LLM)

# Set up GGUF-compatible model (Qwen-1.5, LLaMA, etc.)
# Generates fantasy lore from captions

4. Configuration

  • Replace YOUR_SERVER_IP with your actual server IP address in both:
    • LoreService.swift (iOS app)
    • Info.plist (ATS configuration)
  • Ensure all services are accessible on local network
  • Verify port 3001 (API) and 11434 (LLaVA) are open

๐Ÿ”’ Privacy & Security

iOS Permissions

  • Camera Permission: Required for photo capture
  • Photo Library Permission: Required for image selection
  • No Data Collection: All processing happens locally or on your specified server

Network Security

The API uses HTTP (not HTTPS) for local network communication. iOS requires explicit configuration to allow HTTP traffic:

App Transport Security (ATS) Configuration

Required in Info.plist to enable HTTP connections to local server:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>YOUR_SERVER_IP</key>
    <dict>
      <key>NSExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <key>NSIncludesSubdomains</key>
      <true/>
      <key>NSExceptionRequiresForwardSecrecy</key>
      <false/>
    </dict>
  </dict>
</dict>

Security Notes

  • โš ๏ธ HTTP Only: Suitable for local network development
  • ๐Ÿ  Local Network: All communication stays within your network
  • ๐Ÿ”’ No External Data: Images and lore remain on your devices/servers
  • ๐Ÿ›ก๏ธ Privacy-First: No telemetry or data collection

๐ŸŽจ Design Philosophy

The app embraces a fantasy aesthetic with:

  • ๐Ÿง™โ€โ™‚๏ธ Mystical loading messages ("Consulting the Ancient Texts...")
  • ๐Ÿ“œ Scroll-based visual metaphors
  • โญ Star iconography for favorites and highlights
  • ๐ŸŽจ Warm color palette with orange accents
  • ๐ŸŒ™ Dark mode compatibility

๐Ÿ“ Development Notes

Logging

Comprehensive logging is implemented throughout the app for debugging:

  • ๐ŸŽฏ User interaction tracking
  • ๐Ÿ“ธ Image processing pipeline
  • ๐ŸŒ Network request/response cycles
  • ๐Ÿ’พ Core Data operations
  • ๐Ÿ”„ State management transitions

Error Handling

  • Graceful degradation with mock responses during development
  • User-friendly error messages
  • Automatic retry mechanisms for network failures
  • Comprehensive input validation

๐Ÿค Contributing

This is a personal project, but suggestions and improvements are welcome!

๐Ÿ“„ License

This project is for educational and personal use.


Built with โค๏ธ and a touch of magic โœจ

About

Swift App

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages