Spaces:
Build error
Build error
Download frontend/src/components/TextRequest.js from sp103107/agent-system: direct link, hf CLI and curl.
- Browser
- Download file 4.31 kB
-
https://huggingface.co/spaces/sp103107/agent-system/resolve/main/frontend/src/components/TextRequest.js
- Command line
-
hf download hf://spaces/sp103107/agent-system/frontend/src/components/TextRequest.js
-
curl -L -o TextRequest.js https://huggingface.co/spaces/sp103107/agent-system/resolve/main/frontend/src/components/TextRequest.js
4.31 kB
| import React, { useState } from 'react'; | |
| import axios from 'axios'; | |
| const TextRequest = () => { | |
| const [input, setInput] = useState(''); | |
| const [response, setResponse] = useState(null); | |
| const [loading, setLoading] = useState(false); | |
| const [error, setError] = useState(null); | |
| const handleSubmit = async () => { | |
| setLoading(true); | |
| setError(null); | |
| try { | |
| const result = await axios.post('http://localhost:8000/execute', { | |
| task: { | |
| type: "text_task", | |
| input: input, | |
| auto_team: true // Let the system select appropriate agents | |
| } | |
| }); | |
| setResponse(result.data); | |
| setInput(''); // Clear input after successful submission | |
| } catch (err) { | |
| setError(err.response?.data?.error || 'Error processing request'); | |
| console.error('Request error:', err); | |
| } | |
| setLoading(false); | |
| }; | |
| return ( | |
| <div className="text-request-container"> | |
| <div className="input-section"> | |
| <textarea | |
| value={input} | |
| onChange={(e) => setInput(e.target.value)} | |
| placeholder="Enter your request (e.g., 'Search for Disney hotels and email me the results')" | |
| rows={4} | |
| className="text-input" | |
| /> | |
| <button | |
| onClick={handleSubmit} | |
| disabled={loading || !input.trim()} | |
| className="submit-button" | |
| > | |
| {loading ? 'Processing...' : 'Submit'} | |
| </button> | |
| </div> | |
| {error && ( | |
| <div className="error-message"> | |
| {error} | |
| </div> | |
| )} | |
| {response && ( | |
| <div className="response-section"> | |
| <h3>Response:</h3> | |
| <pre className="response-content"> | |
| {response.formatted_output || JSON.stringify(response, null, 2)} | |
| </pre> | |
| {response.team && ( | |
| <div className="team-info"> | |
| <p>Team: {response.team.join(', ')}</p> | |
| {response.leader && <p>Leader: {response.leader}</p>} | |
| </div> | |
| )} | |
| </div> | |
| )} | |
| <style jsx>{` | |
| .text-request-container { | |
| padding: 20px; | |
| max-width: 800px; | |
| margin: 0 auto; | |
| } | |
| .input-section { | |
| margin-bottom: 20px; | |
| } | |
| .text-input { | |
| width: 100%; | |
| padding: 10px; | |
| margin-bottom: 10px; | |
| border: 1px solid #ccc; | |
| border-radius: 4px; | |
| } | |
| .submit-button { | |
| padding: 10px 20px; | |
| background-color: #007bff; | |
| color: white; | |
| border: none; | |
| border-radius: 4px; | |
| cursor: pointer; | |
| } | |
| .submit-button:disabled { | |
| background-color: #ccc; | |
| } | |
| .error-message { | |
| color: red; | |
| margin: 10px 0; | |
| padding: 10px; | |
| border: 1px solid red; | |
| border-radius: 4px; | |
| } | |
| .response-section { | |
| margin-top: 20px; | |
| padding: 15px; | |
| border: 1px solid #ddd; | |
| border-radius: 4px; | |
| } | |
| .response-content { | |
| white-space: pre-wrap; | |
| background-color: #f5f5f5; | |
| padding: 10px; | |
| border-radius: 4px; | |
| } | |
| .team-info { | |
| margin-top: 10px; | |
| padding-top: 10px; | |
| border-top: 1px solid #ddd; | |
| } | |
| `}</style> | |
| </div> | |
| ); | |
| }; | |
| export default TextRequest; |