diff --git a/.env b/.env
index 98be37a38edd253b4a6d505faf21397a4182b4aa..80ed35459a4f7109c35ebd2fff11d6c5f1f0f60d 100755
--- a/.env
+++ b/.env
@@ -13,4 +13,6 @@ MOODLE_BASE_DIR_DATA=/var/www/html/moodledata
MOODLE_WWWROOT=https://www.moodle.loc
MOODLE_FULLNAME="Moodle LMS Site"
-MOODLE_SHORTNAME="Moodle"
\ No newline at end of file
+MOODLE_SHORTNAME="Moodle"
+
+FLASK_APP=/var/www/html/moodle/api.py
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
index ab9cf7dacaa8f8b69851f9e1a1c410053951982d..f9d3e654b6fd4bc94f982d4a5f011b2e7fffe980 100755
--- a/Dockerfile
+++ b/Dockerfile
@@ -44,6 +44,8 @@ RUN python3 -m venv /opt/myenv
RUN /opt/myenv/bin/python3 -m pip install --upgrade pip
#RUN /opt/myenv/bin/python3 -m pip install matplotlib Flask torch sklearn-learn
COPY requirements.txt /opt/myenv/
+COPY sentence-transformers-paraphrase-multilingual-MiniLM-L12-v2 /var/www/html/moodle/sentence-transformers-paraphrase-multilingual-MiniLM-L12-v2
+WORKDIR /var/www/html/moodle
RUN /opt/myenv/bin/python3 -m pip install -r /opt/myenv/requirements.txt
RUN /opt/myenv/bin/python3 -m pip install --upgrade setuptools wheel
@@ -149,11 +151,6 @@ RUN a2enmod ssl
#Opening ports
EXPOSE 80 443 5000
-#RUN /var/www/html/moodle/install_moodle.sh
-# Run the Flask app (modify entrypoint or use a custom script if needed)
-#CMD ["bash", "-c", "service apache2 start && source /opt/myenv/bin/activate && python3 /var/www/html/moodle/install_moodle.sh /var/www/html/moodle/api.py "]
-#CMD ["bash", "-c", "service apache2 start && source /opt/myenv/bin/activate && python3 /var/www/html/moodle/api.py && /var/www/html/moodle/install_moodle.sh"]
-
# Setting up supervisord
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
diff --git a/api.py b/api.py
index 65c8f170d8c566aaed0cc03234314ba8997ac1d2..43e149029de6a6fd10d8e8333d90a06d10523be6 100755
--- a/api.py
+++ b/api.py
@@ -2,20 +2,33 @@
from flask import Flask, jsonify
+# TODO: Adding correct path to ASYST script run_LR_SBERT.py
+# from run_LR_SBERT import main
+
+# sys.path.append(os.path.join(os.path.dirname(__file__), 'asyst/Source/Skript/german'))
+
app = Flask(__name__)
-# Example of an endpoint returning JSON data
@app.route('/api/data', methods=['GET'])
def get_data():
-# TODO: use run_LR_SBERT.py ASYST script instead
- data = {
+ # Using path to data and model
+ data_path = '/var/www/html/moodle/asyst/Source/Skript/outputs/test.tsv'
+ model_dir = '/var/www/html/moodle/asyst/Source/Skript/german/models'
+
+ # Obtaining results from run_asyst function
+# results => run_asyst(data_path, model_dir)
+
+ # Demo dummy API output
+ results = {
'message': 'Hello from Python API!',
'data': {
'key1': 'value1',
'key2': 'value2'
}
}
- return jsonify(data)
+
+ # Returning result in JSON format
+ return jsonify(results)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
\ No newline at end of file
diff --git a/asyst/Source/Skript/german/run_LR_SBERT.py b/asyst/Source/Skript/german/run_LR_SBERT.py
index e4f169ef1e2fabdd60c40a6e11be5ade14eba3f9..1f01ac6de6a4fecaa24121509200f1bd44e23eea 100755
--- a/asyst/Source/Skript/german/run_LR_SBERT.py
+++ b/asyst/Source/Skript/german/run_LR_SBERT.py
@@ -36,7 +36,6 @@ def main():
#default=None,
default="/var/www/html/moodle/asyst/Source/Skript/outputs/test.tsv",
type=str,
- # required=True,
required=False,
help="The input data file for the task.",
)
@@ -45,7 +44,6 @@ def main():
# default=None,
default="/var/www/html/moodle/asyst/Source/Skript/outputs",
type=str,
- # required=True,
required=False,
help="The output directory where predictions will be written.",
)
@@ -54,32 +52,38 @@ def main():
# default=None,
default=location+"/Skript/german/models",
type=str,
- # required=True,
required=False,
help="The directory where the ML models are stored.",
)
+ parser.add_argument(
+ "--transformer_model_dir",
+ default="/var/www/html/moodle/sentence-transformers-paraphrase-multilingual-MiniLM-L12-v2",
+ type=str,
+ required=False,
+ help="The directory where the SentenceTransformer model is stored.",
+ )
args = parser.parse_args()
# open a log file next to the executable with line buffering
# out = open("log.txt", "a",buffering=1);
- # print("Started German processing in",location,file=out);
+ # print("Started German processing in", location, file=out);
# import SentenceTransformer-model
start_time = time.time()
- # print("Reading from",args.data, file=out);
+ # print("Reading from", args.data, file=out);
- with open(os.path.join(location,args.data)) as ft:
+ with open(args.data) as ft:
dft = pd.read_csv(ft, delimiter='\t')
# Sentences we want sentence embeddings for
sentences1_test = dft['referenceAnswer'].values.tolist()
sentences2_test = dft['studentAnswer'].values.tolist()
- # print("Input read:",sentences2_test, file=out);
+ # print("Input read:", sentences2_test, file=out);
# Use BERT for mapping tokens to embeddings
- word_embedding_model = models.Transformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
+ word_embedding_model = models.Transformer(args.transformer_model_dir)
# pooling operation can choose by setting true (Apply mean pooling to get one fixed sized sentence vector)
pooling_model = models.Pooling(word_embedding_model.get_word_embedding_dimension(),
pooling_mode_mean_tokens=True,
@@ -91,7 +95,7 @@ def main():
# print("Model loaded", file=out);
sentence_embeddings1_test = model.encode(sentences1_test, convert_to_tensor=True, show_progress_bar=False)
- # print("Embeddings RefA:",sentence_embeddings1_test,file=out);
+ # print("Embeddings RefA:", sentence_embeddings1_test, file=out);
sentence_embeddings2_test = model.encode(sentences2_test, convert_to_tensor=True, show_progress_bar=False)
# print("Embeddings found", file=out);
@@ -107,7 +111,7 @@ def main():
# calls the similarity function and get the concatenated values between the sentence embeddings
computed_simis_test = similarity(sentence_embeddings1_test, sentence_embeddings2_test)
- # get the sentence embeddings and the labels fpr train and test
+ # get the sentence embeddings and the labels for train and test
X_test = computed_simis_test
# Y_test = np.array(dft['label'])
@@ -115,12 +119,12 @@ def main():
# UP: read pre-trained LR model
clf_log = pickle.load(open("/var/www/html/moodle/asyst/Source/Skript/german/models/clf_BERT.pickle", "rb"))
-
# print('--------Evaluate on Testset------- ', file=out)
predictions = clf_log.predict(X_test)
# UP print results
with open(args.output_dir + "/predictions.txt", "w") as writer:
+ # TODO: write results to plugins DB Table
writer.write("question\treferenceAnswer\tstudentAnswer\tsuggested grade\tobserved grade\n")
for i in range(len(dft)):
hrpred = "incorrect"
@@ -139,7 +143,7 @@ def main():
+ "\n"
)
- # print('\nExecution time:', time.strftime("%H:%M:%S", time.gmtime(time.time() - start_time)),file=out)
+ # print('\nExecution time:', time.strftime("%H:%M:%S", time.gmtime(time.time() - start_time)), file=out)
if __name__ == "__main__":
diff --git a/docker-compose.yml b/docker-compose.yml
index 0932d6924e080be03aac910f01965be5536db03b..0f8c399c3afdcfd35100e7964c71f946b846f01c 100755
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -42,6 +42,9 @@ services:
- 80:80
- 443:443
- 5000:5000
+ dns:
+ - 8.8.8.8
+ - 8.8.4.4
depends_on: # Dependency from MariaDB service
- mariadb
volumes:
@@ -51,12 +54,6 @@ services:
- moodledata:${MOODLE_BASE_DIR_DATA} # Том для данных Moodle
networks:
- network # Добавление к сети
- healthcheck:
- test: /bin/bash -c 'while ! nc -z mariadb 3306; do echo "Ждем подключения к базе данных..."; sleep 5; done'
- interval: 10s
- timeout: 5s
- retries: 5
- command: [ "bash", "-c", "apache2ctl -D FOREGROUND" ]
volumes:
moodledata:
driver: local # Локальный драйвер томов
diff --git a/install_moodle.sh b/install_moodle.sh
index c26102584d511142c22f1849f1e23a702d9f5c21..49744e2d570f47587c07ee40532185db6d39ed50 100755
--- a/install_moodle.sh
+++ b/install_moodle.sh
@@ -24,8 +24,8 @@ docker-compose exec moodle php ${MOODLE_BASE_DIR}/admin/cli/install.php \
docker-compose exec moodle chmod -R 755 /var/www/html/moodle
# Set correct access rules for the plugin
-#docker-compose exec moodle chown -R www-data:www-data /var/www/html/moodle/mod/yourplugin
-#docker-compose exec moodle chmod -R 775 /var/www/html/moodle/mod/yourplugin
+docker-compose exec moodle chown -R www-data:www-data /var/www/html/moodle/mod/yourplugin
+docker-compose exec moodle chmod -R 775 /var/www/html/moodle/mod/yourplugin
# Create the run_sag script file
docker-compose exec moodle bash -c 'echo "#!/bin/bash" > /usr/local/bin/run_sag'
diff --git a/readme.md b/readme.md
index f3c8a29677dcd66de5f5681a6f43ea20dc18abaf..46c67b3a1bcb202528b19f7677f18ab10165cb18 100755
--- a/readme.md
+++ b/readme.md
@@ -4,11 +4,16 @@ Run these commands at CLI to use ASYST with universal BERT model based on German
~~~bash
docker-compose up -d --build
-install_moodle
+/bin/bash install_moodle.sh
~~~
+Use these creds to access Moodle admin page
+admin:rootpassword
+
+Database connection URL: jdbc:mariadb://localhost:3306/moodle
+
It is suggested to use our moodle plugin to communicate with ASYST script using such a
-route http://127.0.0.1:5000/api/data
+route http://127.0.0.1:5000
Now the preinstalled MOODLE LMS is available at https://www.moodle.loc
diff --git a/supervisord.conf b/supervisord.conf
index 8cc191dbb35d0ee17a4e237fd26fca807d23e097..a5d4e26d4d758a84b4d7b15ae4f1ec93698b4a57 100644
--- a/supervisord.conf
+++ b/supervisord.conf
@@ -5,9 +5,13 @@ nodaemon=true
command=/usr/sbin/apache2ctl -D FOREGROUND
autostart=true
autorestart=true
+stdout_logfile=/var/log/supervisor/flask.log
+stderr_logfile=/var/log/supervisor/flask_err.log
[program:flask]
-command=/opt/myenv/bin/python /var/www/html/moodle/api.py
+command=/bin/bash -c 'source /opt/myenv/bin/activate && FLASK_APP=/var/www/html/moodle/api.py /opt/myenv/bin/flask run --host=0.0.0.0'
directory=/var/www/html/moodle
autostart=true
-autorestart=true
\ No newline at end of file
+autorestart=true
+stdout_logfile=/var/log/supervisor/moodle.log
+stderr_logfile=/var/log/supervisor/moodle_err.log
\ No newline at end of file
diff --git a/yourplugin/db/install.xml b/yourplugin/db/install.xml
new file mode 100644
index 0000000000000000000000000000000000000000..5c484d00f632d802e318ac26a08b5e44735a56f1
--- /dev/null
+++ b/yourplugin/db/install.xml
@@ -0,0 +1,22 @@
+
+
+
+
"; - print_r($data); - echo ""; +// Example: output results echo "
"; + print_r($data); + echo ""; + } else { + echo "Error on data processing from moodlemlbackend!"; + } } else { - echo "Error on data processing from moodlemlbackend!"; + echo "Execution error: result is not a string."; } diff --git a/yourplugin/lib.php b/yourplugin/lib.php new file mode 100644 index 0000000000000000000000000000000000000000..d495ebd96b7f925491b2df98874135665c11bf13 --- /dev/null +++ b/yourplugin/lib.php @@ -0,0 +1,27 @@ +. + +/** + * @package mod_yourplugin + * @author Artem Baranovskyi + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +function mod_yourplugin_before_footer() +{ + if (!get_config('mod_yourplugin', 'enabled')) { + return; + } +} \ No newline at end of file diff --git a/yourplugin/version.php b/yourplugin/version.php index 452923b847f66bcf28f5037b26fdd6754c49eae6..26404c9d6e1a6b9dbac08b87dbced07dc3f572cf 100755 --- a/yourplugin/version.php +++ b/yourplugin/version.php @@ -2,14 +2,14 @@ /** * Version details. * - * @package local_yourplugin + * @package mod_yourplugin * @copyright 2024 Artem Baranovskyi * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2022051101; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2024032201; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2014050800; // Requires this Moodle version. -$plugin->component = 'yourplugin';// Full name of the plugin (used for diagnostics). +$plugin->component = 'mod_yourplugin'; // Full name of the plugin (used for diagnostics). $plugin->cron = 0;