366degrees commited on
Commit
4e40976
·
verified ·
1 Parent(s): 4004780

Delete api_inference.py

Browse files
Files changed (1) hide show
  1. api_inference.py +0 -65
api_inference.py DELETED
@@ -1,65 +0,0 @@
1
- # api_inference.py
2
- import torch
3
- from transformers import AutoTokenizer, AutoModel, AutoConfig
4
- from flask import Flask, request, jsonify
5
- import os
6
-
7
- app = Flask(__name__)
8
-
9
- # === Load Model ===
10
- MODEL_DIR = os.path.dirname(os.path.abspath(__file__))
11
-
12
- print(f"🔍 Loading model from {MODEL_DIR} ...")
13
-
14
- try:
15
- config = AutoConfig.from_pretrained(MODEL_DIR)
16
- tokenizer = AutoTokenizer.from_pretrained(MODEL_DIR)
17
- model = AutoModel.from_pretrained(MODEL_DIR, config=config)
18
- model.eval()
19
- print("✅ SNP Universal Embedding model loaded successfully.")
20
- except Exception as e:
21
- print("❌ Error loading model:", e)
22
- raise e
23
-
24
- # === Define Endpoints ===
25
- @app.route("/")
26
- def index():
27
- return jsonify({
28
- "status": "SNP Universal Embedding API running",
29
- "endpoints": ["/embed", "/reason"]
30
- })
31
-
32
- @app.route("/embed", methods=["POST"])
33
- def embed():
34
- try:
35
- data = request.get_json()
36
- text = data.get("text", "")
37
- if not text:
38
- return jsonify({"error": "No text provided"}), 400
39
-
40
- inputs = tokenizer(text, return_tensors="pt")
41
- with torch.no_grad():
42
- outputs = model(**inputs)
43
- embedding = outputs.last_hidden_state.mean(dim=1).squeeze().tolist()
44
-
45
- return jsonify({"embedding": embedding})
46
- except Exception as e:
47
- return jsonify({"error": str(e)}), 500
48
-
49
- @app.route("/health")
50
- def health():
51
- return "ok", 200
52
-
53
-
54
- @app.route("/reason", methods=["POST"])
55
- def reason():
56
- data = request.get_json()
57
- text = data.get("text", "")
58
- return jsonify({
59
- "text": text,
60
- "reasoning_status": "Feature in development for SNP reasoning structure"
61
- })
62
-
63
- if __name__ == "__main__":
64
- port = int(os.environ.get("PORT", 7860))
65
- app.run(host="0.0.0.0", port=port)