From f1a48d4acb72daff83c17e28c5f407bb81a7f03e Mon Sep 17 00:00:00 2001 From: ALicja Date: Fri, 30 Jan 2026 13:33:51 +0100 Subject: [PATCH] dodanie --- .env | 6 + .gitignore | 2 - .idea/.gitignore | 10 ++ .idea/Strona AI.iml | 10 ++ .idea/inspectionProfiles/Project_Default.xml | 13 ++ .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 7 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + README.md | 3 + app.py | 144 +++++++++++++++++ main.py | 22 --- model.py | 0 models/Power/Readme.md | 1 + .../Power/__pycache__/model.cpython-313.pyc | Bin 0 -> 665 bytes models/Power/description.md | 18 +++ models/Power/meta.json | 6 + models/Power/model.py | 16 ++ static/style.css | 150 ++++++++++++++++++ templates/user.html | 59 +++++++ 20 files changed, 463 insertions(+), 24 deletions(-) create mode 100644 .env delete mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/Strona AI.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 app.py delete mode 100644 main.py create mode 100644 model.py create mode 100644 models/Power/Readme.md create mode 100644 models/Power/__pycache__/model.cpython-313.pyc create mode 100644 models/Power/description.md create mode 100644 models/Power/meta.json create mode 100644 models/Power/model.py create mode 100644 static/style.css create mode 100644 templates/user.html diff --git a/.env b/.env new file mode 100644 index 0000000..a595fb7 --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +SECRET_KEY=MOKO00koko +PASSWORD_KEY=tZnq1IyFSKeBwaLa0Bx5Ge722GgrJztHHNv3jqXMswo= +ADMIN_PASSWORD=admin +MODEL_REPO_URL=https:/git.pathl.pl +UPLOAD_LIMIT_MB=500 +DEBUG=True \ No newline at end of file diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 0949605..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.venv/ -.idea/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/Strona AI.iml b/.idea/Strona AI.iml new file mode 100644 index 0000000..a55366f --- /dev/null +++ b/.idea/Strona AI.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..539dad3 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3769195 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..34f09f4 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index e69de29..ecefae0 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,3 @@ +#Pathl.Ai cześc projektu Cafe + +Ceo: Maro \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..72eb3fb --- /dev/null +++ b/app.py @@ -0,0 +1,144 @@ +from flask import Flask, request, render_template, jsonify, send_from_directory +import os, json, importlib.util +from werkzeug.utils import secure_filename +import markdown +app = Flask(__name__) +UPLOAD_FOLDER = "models" +os.makedirs(UPLOAD_FOLDER, exist_ok=True) +ADMIN_KEY = "supersecretadminkey" + +MODELS = {} + +def load_models(): + for folder in os.listdir(UPLOAD_FOLDER): + path = os.path.join(UPLOAD_FOLDER, folder) + if not os.path.isdir(path): + continue + meta_path = os.path.join(path, "meta.json") + if not os.path.exists(meta_path): + continue + with open(meta_path) as f: + meta = json.load(f) + func_name = meta.get("function_name") + if not func_name: + continue + + py_file = os.path.join(path, "model.py") + spec = importlib.util.spec_from_file_location("model_module", py_file) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + + func = getattr(module, func_name) + MODELS[folder] = { + "func": func, + "inputs": meta.get("inputs", []), + "meta": meta, + "path": path + } + +load_models() + +# ---- DASHBOARD ---- +@app.route("/") +def dashboard(): + models_with_md = {} + for name, model in MODELS.items(): + md_content = "" + try: + md_path = os.path.join(model["path"], model["meta"]["description_file"]) + with open(md_path, "r", encoding="utf-8") as f: + md_text = f.read() + # konwersja Markdown -> HTML + md_content = markdown.markdown(md_text) + except Exception: + md_content = "

Brak opisu.

" + + models_with_md[name] = {**model, "md_content": md_content} + + return render_template("user.html", models=models_with_md) +# ---- PREDICT ---- +@app.route("/predict/", methods=["POST"]) +def predict(model_name): + model_entry = MODELS.get(model_name) + if not model_entry: + return jsonify({"output": "Model nie istnieje"}), 404 + + func = model_entry["func"] + inputs = model_entry["inputs"] + kwargs = {} + for inp in inputs: + kwargs[inp] = request.form.get(inp) + + try: + for k in kwargs: + try: + kwargs[k] = float(kwargs[k]) + except: + pass + output = func(**kwargs) + except Exception as e: + output = str(e) + + return jsonify({"output": str(output)}) + +# ---- ADD MODEL ---- +@app.route("/add_model", methods=["POST"]) +def add_model(): + admin_key = request.form.get("admin_key") + if admin_key != ADMIN_KEY: + return "Brak dostępu", 403 + + name = request.form["name"] + function_name = request.form["function_name"] + inputs = request.form.getlist("inputs") + model_py = request.files["model_py"] + description_file = request.files["description"] + + folder_name = secure_filename(name) + folder_path = os.path.join(UPLOAD_FOLDER, folder_name) + os.makedirs(folder_path, exist_ok=True) + + # zapis plików + model_py.save(os.path.join(folder_path, "model.py")) + description_file.save(os.path.join(folder_path, "description.md")) + + # meta.json + meta = { + "name": name, + "function_name": function_name, + "inputs": inputs, + "description_file": "description.md", + "downloadable": True, # można pobrać pliki + "type": request.form.get("type", "algorithmic") + } + with open(os.path.join(folder_path, "meta.json"), "w") as f: + json.dump(meta, f) + + # załaduj od razu + spec = importlib.util.spec_from_file_location("model_module", os.path.join(folder_path, "model.py")) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + func = getattr(module, function_name) + + MODELS[folder_name] = { + "func": func, + "inputs": inputs, + "meta": meta, + "path": folder_path + } + + return "Dodano model!" + +# ---- DOWNLOAD FILE ---- +@app.route("/download//") +def download_file(model_name, file_name): + model_entry = MODELS.get(model_name) + if not model_entry: + return "Model nie istnieje", 404 + folder_path = model_entry["path"] + if file_name not in ["model.py", "description.md", "meta.json"]: + return "Nieprawidłowy plik", 400 + return send_from_directory(folder_path, file_name, as_attachment=True) + +if __name__ == "__main__": + app.run(debug=True) diff --git a/main.py b/main.py deleted file mode 100644 index 25c9c74..0000000 --- a/main.py +++ /dev/null @@ -1,22 +0,0 @@ -from flask import Flask, request, jsonify - -app = Flask(__name__) - -# Strona główna -@app.route("/") -def home(): - return "AI Pathl Test działa!" - -# Endpoint testowy np. dla promptów AI -@app.route("/test", methods=["POST"]) -def test_ai(): - data = request.json - prompt = data.get("prompt", "") - # Na razie tylko echo promptu - response = {"response": f"Otrzymałem Twój prompt: {prompt}"} - return jsonify(response) - -if __name__ == "__main__": - print("server") - print("dodanie") - app.run(host="0.0.0.0", port=6000) diff --git a/model.py b/model.py new file mode 100644 index 0000000..e69de29 diff --git a/models/Power/Readme.md b/models/Power/Readme.md new file mode 100644 index 0000000..6b8d77d --- /dev/null +++ b/models/Power/Readme.md @@ -0,0 +1 @@ +#model Power diff --git a/models/Power/__pycache__/model.cpython-313.pyc b/models/Power/__pycache__/model.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ecf8832be9f1ce6ad1fe9f614a2383c59b35ec86 GIT binary patch literal 665 zcmYjPL5tHs6rM@l-8S7)4}zeVM-jRKZS)#MSOvk$QYee!MW)Hv&Ni6|lf*Q^g9ze! z+shurn>Wv1z1jYPUY49hPkUR)A8;m(!3X)0@4ffE_vTH?Ue83z%CB$P1|#%GlYgdo zWu;CzM-y}lNi@Tj;Tm;Bzw~!YJ>`7`=ja$uu=4^TvV+huni%)m2;I@%)_>k>TkmYg z+D(2dnfWx~3-^S8nEK4k2`p0LNfLvfOd-nY`isj52OXPcu!IzH;?wmHE_4Kh2O*Ip zps`FK&ccy7u4(3&OE_RWwqN^##Fn$ILGHpL{`p<5K7c!SX^=rEJkC^~)kpAzV)5$p zjG3wy97M5HxB<0wW6woEZB7NZ z$C*1PG8jv7LftsBC$SWqz~M7H5FYg-dn{5aw`3G%MQ?inuhatQj7WX)`Y(tq1@F++ z4b<+Qvd!Mji~jYq!%uHcdl#Mkv+kyIyK(&LKQ2`=I4_zA9({{r + + + AI Models + + + + +

Lista modeli AI

+
+ {% for name, model in models.items() %} +
+

{{name}}

+
+ {{ model.md_content | safe }} +
+ + +
+ {% for inp in model.inputs %} + +
+ {% endfor %} + +
+
+ {% if model.meta.downloadable %} + + {% endif %} +
+
+ {% endfor %} +
+ + + +