Can a python script run on wordpress and can i create a plugin that uses that ?
I have to make a custom chatbot . I have the code that works perfect however there are some issues that i have in front of me.
Firstly the main one , wordpress being full php can i run some python code somehow and also some javascript for the aspect of the chatbot ?
Also the other issue that i have is that i am using a pretraied model from Vertex AI in google cloud , and if i want to call this API i have to open a cmd and login with my google account with this commands :pip install --upgrade google-cloud-aiplatformgcloud auth application-default login
By doing this i get a window in my browser where i have to login .
I havent really found a specific guide or tutorial yet and wondered if anyone encountered this before while making a wordpress plugin .
I already made a version that works locally with flask .
Is this even possible to do ? My hosting provider gives me C-Panel , maybe there is a way through there ?
this is my python code so far with flask :
# Initialize Vertex AIvertexai.init(project="redacted", location="redacted")model = GenerativeModel("redacted")# Define the chat functiondef multiturn_generate_content(messages): if 'context' not in session or not session['context']: return ["No context initialized. Please set the context first."] # Initialize the model with context model = GenerativeModel("gemini-1.0-pro-002", system_instruction=[session['context']] ) chat = model.start_chat() responses = [] for msg in messages: response = chat.send_message( [msg], generation_config={"max_output_tokens": 1024,"temperature": 0.2,"top_p": 0.8 }, safety_settings={ generative_models.HarmCategory.HARM_CATEGORY_HATE_SPEECH: generative_models.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE, generative_models.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: generative_models.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE, generative_models.HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: generative_models.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE, generative_models.HarmCategory.HARM_CATEGORY_HARASSMENT: generative_models.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE, } ) if response and response.candidates: for candidate in response.candidates: if candidate.content and candidate.content.parts: text_response = ''.join(part.text for part in candidate.content.parts if part.text) responses.append(text_response) return responses@app.route('/set_context', methods=['POST'])def set_context(): data = request.json session['context'] = data.get('context', '') if session['context']: return jsonify({"message": "Context set successfully"}), 200 else: return jsonify({"error": "No context provided"}), 400# Define a route for the chat@app.route('/chat', methods=['POST'])def chat(): messages = request.json.get('messages', []) responses = multiturn_generate_content(messages) return jsonify({"responses": responses}) # This should now be properly serializable