Crypto Sights
  • Getting Started
  • Data Acquisition
  • Data Preprocessing
  • Sentiment Analysis
  • Backend
  • Frontend
  • Frontend
  • Evaluation
Powered by GitBook
On this page
  • Frontend API Interaction – script.js
  • UI Structure and Styling – index.html & style.css
Export as PDF

Frontend

Frontend API Interaction – script.js

The file `script.js` handles form submissions and frontend-to-backend communication. It gathers input values from HTML elements, packages them into a JSON payload, and sends them via the Fetch API to the Flask server. Error responses are caught and displayed gracefully. The JavaScript also formats and renders the returned sentiment and answer list in the frontend UI dynamically.

UI Structure and Styling – index.html & style.css

The user interface is built using HTML5, styled with modern CSS for responsiveness and dark mode compatibility. Elements include: - Coin selection dropdown (`<select>`) - Query input field (`<input>`) - Submission button (`<button>`) - Output div (`<div id="result">`)

Light Frontend work:

script.js

Purpose: Bridges frontend form with backend API.

function sendQuery() {
  const coin = document.getElementById('coin').value;
  const query = document.getElementById('query').value;
  ...
  fetch('/query', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ coin, query })
  })

Core Logic:

  • Sends a POST request to /query

  • Parses and displays response

  • Handles errors and displays fallback messages

Helper:

const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1);

Used to format the coin name before displaying.

index.html and style.css

index.html: Standard HTML form including:

  • Dropdown for coin selection

  • Input field for query

  • Submit button to trigger sendQuery()

  • Result placeholder

style.css:

Custom styling:

  • Dark theme with soft shadows

  • Responsive form fields

  • Visual feedback on hover

Links:

Quick Links for reference:

Flask

Flask-CORS

render_template

request.get_json()

JSON module

os module

datetime

Fetch API

HTML form elements

CSS styling

PreviousFrontendNextEvaluation

Last updated 29 days ago

Link to Fetch API Docs:

Fetch API – MDN
HTML Select Element – MDN
CSS Styling Basics – MDN
https://flask.palletsprojects.com/
https://flask-cors.readthedocs.io/en/latest/
https://flask.palletsprojects.com/en/2.3.x/api/#flask.render_template
https://flask.palletsprojects.com/en/2.3.x/api/#flask.Request.get_json
https://docs.python.org/3/library/json.html
https://docs.python.org/3/library/os.html
https://docs.python.org/3/library/datetime.html
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
https://developer.mozilla.org/en-US/docs/Learn/CSS