Back

Unable to execute function

  • 0
  • React Native
  • Functions
  • Cloud
alainpaul
8 Dec, 2024, 15:15

i wanna also ask why im facing the error in appwrite functions

Traceback (most recent call last): File "/usr/local/server/src/server.py", line 106, in action output = await asyncio.waitfor(execute(context), timeout=safeTimeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/tasks.py", line 489, in waitfor return fut.result() ^^^^^^^^^^^^ File "/usr/local/server/src/server.py", line 91, in execute userModule = importlib.import_module("function." + userPath) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/importlib/__init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1204, in _gcd_import File "<frozen importlib._bootstrap>", line 1176, in _find_and_load File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 690, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 940, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "/usr/local/server/src/function/function.py", line 2, in <module> import tensorflow as tf ModuleNotFoundError: No module named 'tensorflow' even if i picked the Python ML 3.11 and wrote the install requirements in txt and when i check and download the code from deployment that appwrite chosen - everything is written ok, but i cant execute it

TL;DR
The developers are unable to execute the function due to an error related to a missing TensorFlow module. The error occurs during the execution of the appwrite functions. The traceback indicates that the 'tensorflow' module is not found, even though Python ML 3.11 and the required dependencies were specified in the requirements.txt file. The deployment code seems correct, but the issue persists. Solution: Ensure that TensorFlow is properly installed and accessible in the environment where the function is executed. Double-check the installation process and dependencies to resolve the 'No module named 'tensorflow'' error.
D5
8 Dec, 2024, 15:24

What's the code or part that throws the error?

alainpaul
8 Dec, 2024, 15:28

import json import tensorflow as tf import numpy as np import pickle from flask import Flask, request, Response

alainpaul
8 Dec, 2024, 15:29

`import json import tensorflow as tf import numpy as np import pickle from flask import Flask, request, Response

app = Flask(name)

Загрузка модели и токенайзера при старте приложения

model = tf.keras.models.load_model('text_model.h5') with open('tokenizer.pkl', 'rb') as f: tokenizer = pickle.load(f)

def generate_next_word(prompt): """ Генерация следующего слова на основе переданной строки prompt. """ # Преобразование текста в последовательность sequence = tokenizer.texts_to_sequences([prompt])[0] if len(sequence) < 5: padded = tf.keras.preprocessing.sequence.pad_sequences([sequence], maxlen=5) else: padded = np.array([sequence[-5:]])

TypeScript
# Предсказание следующего слова
prediction = model.predict(padded)
next_word_id = np.argmax(prediction)

# Поиск слова по индексу
for word, index in tokenizer.word_index.items():
    if index == next_word_id:
        return word
return ""

@app.route('/', methods=['POST']) def main(): """ Главная функция обработки POST-запроса. """ try: # Получаем данные от клиента data = request.get_json() prompt = data.get('prompt', '')

TypeScript
    # Генерируем следующее слово
    next_word = generate_next_word(prompt)

    # Формируем JSON-ответ
    response_data = {"next_word": next_word}
    return Response(json.dumps(response_data, ensure_ascii=False), mimetype='application/json')
except Exception as e:
    # Обработка ошибок
    error_response = {"error": str(e)}
    return Response(json.dumps(error_response, ensure_ascii=False), mimetype='application/json', status=500)

if name == "main": app.run(host='0.0.0.0', port=3000)`

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more