Skip to content

Commit efbb2b6

Browse files
committed
feat: Add demo mode for web version without API key
- Added demo mode functionality that works without requiring an API key - Created getDemoResponses function with sample chat messages - Modified getAIInstance to return null when no API key is available - Updated generateChatResponses to use demo mode when no API key - Added demo mode indicator in UI with warning notice - Users can now try the app immediately without API key setup - Demo mode shows sample responses and guides users to get API key
1 parent e81c615 commit efbb2b6

4 files changed

Lines changed: 144 additions & 67 deletions

File tree

WebApp.tsx

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function WebApp() {
4545
const [responses, setResponses] = useState<any>(undefined);
4646
const [error, setError] = useState<string | undefined>(undefined);
4747
const [isLoading, setIsLoading] = useState(false);
48+
const [isDemoMode, setIsDemoMode] = useState(false);
4849

4950
// --- Handlers ---
5051
const triggerFileInput = useCallback(() => {
@@ -67,6 +68,11 @@ function WebApp() {
6768
try {
6869
const response = await generateChatResponses(imageToUse || '', makeItFunnier, customPrompt, messageCount);
6970
setResponses(response);
71+
// Check if we're in demo mode by looking for demo messages
72+
const isDemo = response.chatMessages?.some((msg: any) =>
73+
['look at this screenshot', 'wow what a view', 'this game is amazing'].includes(msg.message || msg.text)
74+
);
75+
setIsDemoMode(isDemo);
7076
} catch (err: any) {
7177
setError(err?.message || 'Failed to generate chat messages');
7278
} finally {
@@ -242,9 +248,23 @@ function WebApp() {
242248
<Typography variant="h4" component="h1" gutterBottom sx={{ fontWeight: 'bold' }}>
243249
New World Chat AI
244250
</Typography>
245-
<Typography variant="body1" color="text.secondary" gutterBottom>
246-
Upload an image or drag and drop to generate chat messages
247-
</Typography>
251+
<Typography variant="body1" color="text.secondary" gutterBottom>
252+
Upload an image or drag and drop to generate chat messages
253+
</Typography>
254+
<Box sx={{ mt: 2, p: 2, backgroundColor: 'rgba(255, 193, 7, 0.1)', borderRadius: '8px', border: '1px solid rgba(255, 193, 7, 0.3)' }}>
255+
<Typography variant="body2" color="warning.main" sx={{ textAlign: 'center' }}>
256+
💡 <strong>Demo Mode:</strong> No API key configured. Get your free API key from{' '}
257+
<a
258+
href="https://aistudio.google.com/app/apikey"
259+
target="_blank"
260+
rel="noopener noreferrer"
261+
style={{ color: '#00bcd4', textDecoration: 'none' }}
262+
>
263+
Google AI Studio
264+
</a>
265+
{' '}for full AI-powered responses!
266+
</Typography>
267+
</Box>
248268
</Box>
249269

250270
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2, alignItems: 'center' }}>
@@ -306,9 +326,26 @@ function WebApp() {
306326
{responses && responses.chatMessages && (
307327
<Box sx={{ mt: 3, width: '100%' }}>
308328
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 2 }}>
309-
<Typography variant="h6">
310-
Generated Messages:
311-
</Typography>
329+
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
330+
<Typography variant="h6">
331+
Generated Messages:
332+
</Typography>
333+
{isDemoMode && (
334+
<Box
335+
sx={{
336+
px: 1,
337+
py: 0.5,
338+
backgroundColor: 'rgba(255, 193, 7, 0.2)',
339+
border: '1px solid #ffc107',
340+
borderRadius: '4px',
341+
fontSize: '0.75rem',
342+
color: '#ffc107'
343+
}}
344+
>
345+
DEMO MODE
346+
</Box>
347+
)}
348+
</Box>
312349
<Button
313350
size="small"
314351
variant="outlined"

0 commit comments

Comments
 (0)