Spaces:
Running
Running
Download src/components/ChatInterface.jsx from tung14/deepsite-project: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/spaces/tung14/deepsite-project/resolve/main/src/components/ChatInterface.jsx
- Command line
-
hf download hf://spaces/tung14/deepsite-project/src/components/ChatInterface.jsx
-
curl -L -o ChatInterface.jsx https://huggingface.co/spaces/tung14/deepsite-project/resolve/main/src/components/ChatInterface.jsx
1.5 kB
| ```javascript | |
| import { useState } from 'react' | |
| import { Send, Loader } from 'react-feather' | |
| export default function ChatInterface({ messages, onSend, isLoading }) { | |
| const [input, setInput] = useState('') | |
| const handleSubmit = (e) => { | |
| e.preventDefault() | |
| if (!input.trim()) return | |
| onSend(input) | |
| setInput('') | |
| } | |
| return ( | |
| <div className="flex flex-col h-full"> | |
| <div className="flex-1 overflow-y-auto p-4"> | |
| {messages.map((msg, i) => ( | |
| <div key={i} className={`mb-4 ${msg.role === 'user' ? 'text-right' : 'text-left'}`}> | |
| <div className={`inline-block p-3 rounded-lg ${msg.role === 'user' | |
| ? 'bg-blue-500 text-white' | |
| : 'bg-gray-200 text-gray-800'}`}> | |
| {msg.content} | |
| </div> | |
| </div> | |
| ))} | |
| </div> | |
| <form onSubmit={handleSubmit} className="p-4 border-t"> | |
| <div className="flex"> | |
| <input | |
| type="text" | |
| value={input} | |
| onChange={(e) => setInput(e.target.value)} | |
| className="flex-1 p-2 border rounded-l-lg focus:outline-none" | |
| placeholder="Type your message..." | |
| /> | |
| <button | |
| type="submit" | |
| disabled={isLoading} | |
| className="bg-blue-500 text-white p-2 rounded-r-lg hover:bg-blue-600 disabled:bg-blue-300"> | |
| {isLoading ? <Loader className="animate-spin" /> : <Send />} | |
| </button> | |
| </div> | |
| </form> | |
| </div> | |
| ) | |
| } | |
| ``` |