An immersive AI-powered text adventure game that combines the storytelling prowess of Google's Gemini 2.0 Flash with the visual creativity of Cloudflare's AI image generation. Every choice you make shapes both the narrative and the accompanying artwork in real-time.
- ๐ช Dynamic Storytelling: Powered by Gemini 2.0 Flash for rich, contextual narratives
- ๐จ Real-time Image Generation: Cloudflare's stable-diffusion-xl-lightning creates stunning visuals for every scene
- โก Lightning-fast Responses: Optimized for quick story progression and image generation
- ๐ฎ Interactive Gameplay: Your actions directly influence the story direction
- ๐ฑ Responsive Design: Beautiful UI that works on desktop and mobile
- ๐ Seamless Experience: Smooth transitions between story beats with visual feedback
- Frontend: React 19 + TypeScript + Tailwind CSS
- Build Tool: Vite with ES modules
- AI Services:
- Google Gemini 2.0 Flash (text generation)
- Cloudflare Workers AI (image generation)
- Backend: Express.js proxy server for CORS handling
- Styling: Tailwind CSS with custom gradients and animations
Before you begin, ensure you have:
- Node.js (version 16 or higher)
- npm or yarn package manager
- Google Gemini API Key (free tier available)
- Cloudflare API Key and Account ID
git clone https://github.com/Khushal-Me/Simulated-Souls
cd Simulated-Souls
npm installCreate a .env.local file in the root directory:
# Google Gemini API Key (for storytelling)
GEMINI_API_KEY=your_gemini_api_key_here
# Cloudflare API Key (for image generation)
CLOUDFLARE_API_KEY=your_cloudflare_global_api_key_hereUpdate your Cloudflare Account ID in proxy-server/server.js:
const ACCOUNT_ID = 'your_cloudflare_account_id_here';cd proxy-server
npm install
cd ..Terminal 1 - Start the proxy server:
node proxy-server/server.jsTerminal 2 - Start the main application:
npm run devOpen your browser and navigate to http://localhost:5173
Demo.mp4
- Visit Google AI Studio
- Sign in with your Google account
- Click "Create API Key"
- Copy the generated key to your
.env.localfile
- Log in to Cloudflare Dashboard
- Go to "My Profile" โ "API Tokens"
- Scroll to "Global API Key" and click "View"
- Copy the key to your
.env.localfile - Find your Account ID in the right sidebar of any domain dashboard
- Update the
ACCOUNT_IDinproxy-server/server.js
gemini-adventure-weaver/
โโโ ๐ components/ # React components
โ โโโ ErrorMessage.tsx # Error display component
โ โโโ LoadingSpinner.tsx # Loading animation component
โโโ ๐ proxy-server/ # Express.js CORS proxy
โ โโโ server.js # Proxy server for Cloudflare API
โ โโโ package.json # Proxy dependencies
โโโ ๐ services/ # API service layer
โ โโโ geminiService.ts # Gemini & Cloudflare integrations
โโโ App.tsx # Main application component
โโโ index.tsx # Application entry point
โโโ types.ts # TypeScript type definitions
โโโ vite.config.ts # Vite configuration
โโโ .env.local # Environment variables (create this)
- Start: Click "Begin Your Adventure" to initialize your story
- Read: Enjoy the AI-generated scene description and accompanying artwork
- Act: Type your action in the input field (e.g., "open the door", "talk to the wizard")
- Watch: See how your choices influence both the story and generated images
- Continue: Keep making choices to weave your unique adventure
- Restart: Use the "Restart Adventure" button to begin a new story
Customize the storytelling behavior by modifying the SYSTEM_INSTRUCTION in services/geminiService.ts.
๐ซ CORS Errors
- Ensure the proxy server is running on port 3001
- Check that
proxy-server/server.jsis properly configured
๐ API Authentication
- Verify your
.env.localfile exists and contains valid API keys - Check the proxy server status at
http://localhost:3001/api/status - Ensure your Cloudflare account has Workers AI enabled
๐ผ๏ธ Image Generation Failures
- Verify your Cloudflare Account ID is correct
- Check your Cloudflare API quota and billing status
- Ensure you're using the Global API Key, not a scoped token
๐ Network Issues
- Make sure ports 3001 and 5173 are available
- Check your firewall settings
- Verify internet connectivity for API calls
Check proxy server status:
curl http://localhost:3001/api/statusTest image generation:
curl -X POST http://localhost:3001/api/generate-image \
-H "Content-Type: application/json" \
-d '{"prompt": "a magical forest"}'npm run dev # Start development servernpm run build # Build for production
npm run preview # Preview production build- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is open source and available under the MIT License.
If you encounter any issues or have questions:
- Check the troubleshooting section
- Review the Cloudflare setup guide
- Open an issue on GitHub
- Check API status pages for service outages