How to run Flask App from Arduino Output

Hi!
I'm building an ATM with an Arduino and Coin Acceptor (CH-926) which should be connected to a Webapp, for what I'm using flask. Currently my problem is that I can only use my flask Webapp if I have inserted a coin into the Coin Acceptor, otherwise I can't proceed to my /getbitcoin/ route and get an "ERR_CONNECTION_REFUSED" .
I assume the Flask App can only run, if it gets an Output or High state from the Arduino.

I want to be able to go the the route and then insert the coins in the Coin Acceptor.

This is the Arduino Script I'm using:

const int coinSelector = A0; // Analog input pin that the coin selector uses
const int signalCostFactor = 5; // Each signal pulse is worth 5p

int signalValue = 0; // For storing value from analog input

int state; // Current state
int lastState = 0; // Last state

int balance = 0; // Pence
int coinValue = 0; // Curent coin value

int update = 1; // Used for sending an update

long updateDebounceTime = 0; // The last time we sent an update
long updateDebounceDelay = 500; // Update 500ms after last singal pulse

void setup() {

  pinMode(13, OUTPUT); // Status LED

  Serial.begin(9600); // Setup serial at 9600 baud

  delay(2000); // Don't start main loop until we're sure that the coin selector has started

  Serial.println("Ready..");

}

void loop() {

  signalValue = analogRead(coinSelector); // Read analog value from coin selector

  if (signalValue > 1000) {

    state = 1; // State is 1 as we're high

  } else {

    state = 0;

    // Should we send a balance update

    if (update == 0) {

      if ((millis() - updateDebounceTime) > updateDebounceDelay) {

        Serial.print("Coin Value: ");
        Serial.println(coinValue); // WARNING: The coin value will be wrong if coins are inserted within the updateDebounceDelay, adjust the delay and test

        Serial.print("Balance: ");
        Serial.println(balance); // This should be the most accurate as we should get the same ammount of pulses even if multiple coins get inserted at once

        coinValue = 0; // Reset current coin value

        update = 1; // Make sure we don't run again, till next coin

      }

    }

  }

  if (state != lastState) {

    // Process new signal

    if (state == 1) {

      digitalWrite(13, HIGH); // Turn status LED on to show signal

      balance = balance + signalCostFactor; // Update balance

      coinValue = coinValue + signalCostFactor; // Update coin value

      updateDebounceTime = millis(); // Update last time we processed a signal

      update = 0; // Time to send a update now?

    } else {

      digitalWrite(13, LOW);  // Turn status LED off

    }

    lastState = state; // Update last state

 }

  delay(1);

 }

And this is the Python/Flask Script:

from flask import Flask
from flask import render_template
import serial

app = Flask(__name__)


arduino = serial.Serial("/dev/tty.usbmodem411", 9600, timeout=1) # Connect to Arduino  



@app.route("/")
def home():
    return render_template("home.html")

@app.route("/getbitcoin/")
def getbitcoin():

    value = arduino.readline()
    balance = arduino.readline()
    print(value.rstrip())
    print(balance.rstrip())

    return render_template("getbitcoin.html", balance = balance)



if __name__ == "__main__":

    app.run(port=5000, host='0.0.0.0', debug = True, use_reloader=True)

Let me know if I'm at the right forum for this question!

Thank you!