import React, { useState, useRef } from 'react'; import { GeminiService } from '../geminiService'; import Markdown from 'react-markdown'; const MoltBotView: React.FC = () => { const [messages, setMessages] = useState<{ role: 'user' | 'model', content: string, image?: string }[]>([]); const [input, setInput] = useState(''); const [image, setImage] = useState(null); const [isLoading, setIsLoading] = useState(false); const fileInputRef = useRef(null); const handleImageUpload = (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (file) { const reader = new FileReader(); reader.onloadend = () => { setImage(reader.result as string); }; reader.readAsDataURL(file); } }; const handleSend = async () => { if (!input.trim() && !image) return; const userMsg = { role: 'user' as const, content: input, image: image || undefined }; setMessages(prev => [...prev, userMsg]); setInput(''); setImage(null); setIsLoading(true); try { let responseText = ''; if (userMsg.image) { // Multimodal call const base64Data = userMsg.image.split(',')[1]; const mimeType = userMsg.image.split(';')[0].split(':')[1]; const result = await GeminiService.vision(userMsg.content || "What is in this image?", base64Data, mimeType); responseText = result.text; } else { // Chat call const result = await GeminiService.chat(userMsg.content); responseText = result.text; } setMessages(prev => [...prev, { role: 'model', content: responseText }]); } catch (error) { setMessages(prev => [...prev, { role: 'model', content: "Bhai, error aa gaya! Shayad API key ya network ka issue hai." }]); } finally { setIsLoading(false); } }; return (
{messages.length === 0 && (

MoltBot Multimodal

Upload images and ask questions. I can see and reason.

)} {messages.map((m, i) => (
{m.image && ( User upload )}
{m.content}
))} {isLoading && (
MoltBot is thinking...
)}
{image && (
Preview
)}
setInput(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && handleSend()} placeholder="Ask MoltBot anything about images or text..." className="flex-1 bg-[#0a0f1e] border border-white/5 rounded-2xl px-6 py-4 text-white placeholder:text-slate-600 focus:border-orange-500 outline-none transition-all" />
); }; export default MoltBotView;