File size: 1,067 Bytes
f332108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Popup.js
import React, { useState } from 'react';
import axios from 'axios';

const Popup = () => {
    const [message, setMessage] = useState(''); // Message user types in
    const [response, setResponse] = useState(''); // Response from the backend

    const sendQuery = async () => {
        try {
            const result = await axios.post('http://0.0.0.0:8000/query', { query: message });
            setResponse(result.data.response);
        } catch (error) {
            setResponse('Error communicating with the server.');
        }
    };

    return (
        <div className="chatbox">
            <input 
                type="text" 
                value={message} 
                onChange={e => setMessage(e.target.value)} 
                className="chat-input"
                placeholder="Type your message..."
            />
            <button onClick={sendQuery} className="chat-send-btn">Send</button>
            <div className="response-box">
                {response}
            </div>
        </div>
    );
};

export default Popup;