Skip to content

Commit

Permalink
Refs #21906: Update Front-end to send data
Browse files Browse the repository at this point in the history
Signed-off-by: eProsima <jesuspoderoso@eprosima.com>
  • Loading branch information
JesusPoderoso committed Oct 22, 2024
1 parent bee3612 commit 370f6c5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sustainml_modules/sustainml_modules/sustainml-wp4/frontend_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,15 @@ def get_geolocation():
except Exception as e:
return jsonify({'error': str(e)}), 500

@app.route('/send_pd', methods=['POST'])
def send_pd():
try:
data = request.json
# pipe the information to the backend
requests.post('http://127.0.0.1:5001/user_input', json=data)
return jsonify({'message': 'Data successfully sent'}), 200
except Exception as e:
return jsonify({'error': str(e)}), 500

if __name__ == '__main__':
app.run(debug=True)
37 changes: 37 additions & 0 deletions sustainml_modules/sustainml_modules/sustainml-wp4/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<p>Model's suggestion?</p>
<select id="model-select"></select>
</div>
<div id="submit-pd" class="hidden">
<button class="response-button">Submit PD Info</button>
</div>
</div>
<!-- Environment section -->
<div id="env-section" class="hidden">
Expand Down Expand Up @@ -177,12 +180,46 @@ <h2>Environment Information</h2>
option.textContent = model;
modelSelect.appendChild(option);
});
modelSelect.addEventListener('change', function() {
document.getElementById('submit-pd').style.display = 'block';
});
})
.catch(error => {
console.error('Failed to fetch filtered options:', error);
});
}

document.getElementById('submit-pd').addEventListener('click', function() {
const modality = document.getElementById('modality-select').value;
const problemType = document.getElementById('problem-type-select').value;
const evaluationMetrics = document.getElementById('evaluation-metrics-select').value;
const model = document.getElementById('model-select').value;

// Handle the PD data submission (e.g., send it to your server)
const pdData = {
modality,
problemType,
evaluationMetrics,
model
};

console.log('PD Data:', pdData);
fetch('/send_pd', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
'modality': modality,
'problem_type': problemType,
'evaluation_metrics': evaluationMetrics,
'model': model
})
})
.then(response => response.json())
.then(data => {
// Show results ?
})
});

// Handle the environment submission
document.getElementById('submit-environment').addEventListener('click', function() {
const hardware = document.getElementById('hardware-input').value;
Expand Down

0 comments on commit 370f6c5

Please sign in to comment.