Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
how to get a value from a python code to a Javascript variable in JS file

I'm trying to develop the frontend in Javascript for a voice bot, which was written in python

if hi == 0:
    talk('hello iam kavi')
    print('hello iam kavi Voice assistant')
    talk('How are you buddy!!!')
    print('How are you buddy!!!')
    talk('doing good right?????')
    print('doing good right?????')

In the code above, instead of printing it on the terminal, I want it to be sent to Javascript code, which looks like below

class MessageParser {
  constructor(ActionProvider, state) {
    this.actionProvider = ActionProvider;
    this.state = state;
  }

  parse(message) {
    const lowerCaseMessage = message.toLowerCase()
    
    if (lowerCaseMessage.includes("hello")) {
      this.actionProvider.greet();
    }
    else{
      this.actionProvider.listening();
    }
  }
}

export default MessageParser;

where the printed text in the python code should be sent as message variable into parse(message) function.

I'm a beginner at Javascript and React, any help is appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to build an API in Python, to send the data to React. The fastest way will probably be using flask, it could look like this:

from flask import Flask

app = Flask(__name__)

@app.route('/talk', methods=['GET'])
def talk():
    return talk("whatever")

Then from react you can get the message using fetch, axios or any other option in the componentDidMount or componentDidUpdate depending on your needs. Please, note that I don't know how your talk function works so you'll have to adapt the code to send the correct message to the frontend.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda