EdgeLLMModal1 commited on
Commit
7464e08
·
verified ·
1 Parent(s): d368375

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +13 -0
  2. app.py +102 -0
  3. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ RUN apt update && apt install -y git build-essential cmake && apt clean
4
+
5
+ WORKDIR /app
6
+
7
+ COPY requirements.txt .
8
+ RUN pip install --no-cache-dir -r requirements.txt
9
+
10
+ COPY model/ ./model/
11
+ COPY app.py .
12
+
13
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request
2
+ from llama_cpp import Llama
3
+ import requests
4
+ from bs4 import BeautifulSoup
5
+
6
+ ENV_URL = "http://192.168.4.1/" # your Station AP page
7
+
8
+ llm = Llama(model_path="model/llama-3.2-1b-Q4_K_M.gguf")
9
+
10
+ app = Flask(__name__)
11
+
12
+ def fetch_envpro_values():
13
+ r = requests.get(ENV_URL, timeout=3)
14
+ soup = BeautifulSoup(r.text, "html.parser")
15
+ text = soup.get_text()
16
+
17
+ def extract(label):
18
+ start = text.find(label)
19
+ if start == -1:
20
+ return None
21
+ value = text[start+len(label):].split("\n")[0].strip()
22
+ return value
23
+
24
+ return {
25
+ "temp": extract("Temp:"),
26
+ "hum": extract("Hum:"),
27
+ "press": extract("Press:"),
28
+ "gas": extract("Gas:"),
29
+ "co2": extract("CO2eq:"),
30
+ "voc": extract("VOCeq:"),
31
+ "iaq": extract("IAQ accuracy:")
32
+ }
33
+
34
+ @app.route("/interpret")
35
+ def interpret():
36
+ data = fetch_envpro_values()
37
+
38
+ prompt = (
39
+ "ENV PRO DATA:\n"
40
+ f"Temp: {data['temp']}\n"
41
+ f"Hum: {data['hum']}\n"
42
+ f"Press: {data['press']}\n"
43
+ f"Gas: {data['gas']}\n"
44
+ f"CO2eq: {data['co2']}\n"
45
+ f"VOCeq: {data['voc']}\n"
46
+ f"IAQ accuracy: {data['iaq']}\n\n"
47
+ "Context: Indoor environment. Do not assume cooking unless the sensor values indicate it.\n"
48
+ "Instruction: Base your interpretation ONLY on the ENV PRO DATA values above.\n"
49
+ "Do NOT invent activities.\n"
50
+ "Do NOT infer smells that are not supported by the data.\n"
51
+ "The environment may be a bedroom, living room, hallway, kitchen or any indoor space.\n\n"
52
+ "Task: Output exactly ONE short sentence.\n"
53
+ "Rules:\n"
54
+ "1. The sentence MUST start with one of these words: smell, activity, mood, doing\n"
55
+ "2. The sentence MUST NOT exceed 100 characters.\n"
56
+ "3. Do NOT output examples.\n"
57
+ "4. Do NOT output lists.\n"
58
+ "5. Do NOT explain anything.\n"
59
+ "6. Output exactly ONE short sentence.\n\n"
60
+ "Now output the sentence:\n"
61
+ )
62
+
63
+ out = llm(prompt, max_tokens=160)
64
+ return out["choices"][0]["text"]
65
+
66
+ # ⭐ NEW: Manual input mode (works inside Docker Desktop)
67
+ @app.route("/manual", methods=["POST"])
68
+ def manual():
69
+ data = request.json
70
+
71
+ prompt = (
72
+ "ENV PRO DATA:\n"
73
+ f"Temp: {data['temp']}\n"
74
+ f"Hum: {data['hum']}\n"
75
+ f"Press: {data['press']}\n"
76
+ f"Gas: {data['gas']}\n"
77
+ f"CO2eq: {data['co2']}\n"
78
+ f"VOCeq: {data['voc']}\n"
79
+ f"IAQ accuracy: {data['iaq']}\n\n"
80
+ "Context: Indoor environment. Do not assume cooking unless the sensor values indicate it.\n"
81
+ "Instruction: Base your interpretation ONLY on the ENV PRO DATA values above.\n"
82
+ "Do NOT invent activities.\n"
83
+ "Do NOT infer smells that are not supported by the data.\n"
84
+ "The environment may be a bedroom, living room, hallway, kitchen or any indoor space.\n\n"
85
+ "Task: Output exactly ONE short sentence.\n"
86
+ "Rules:\n"
87
+ "1. The sentence MUST start with one of these words: smell, activity, mood, doing\n"
88
+ "2. The sentence MUST NOT exceed 100 characters.\n"
89
+ "3. Do NOT output examples.\n"
90
+ "4. Do NOT output lists.\n"
91
+ "5. Do NOT explain anything.\n"
92
+ "6. Output exactly ONE short sentence.\n\n"
93
+ "Now output the sentence:\n"
94
+ )
95
+
96
+ out = llm(prompt, max_tokens=160)
97
+ return out["choices"][0]["text"]
98
+
99
+ app.run(host="0.0.0.0", port=8000)
100
+
101
+
102
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ flask
2
+ llama-cpp-python
3
+ requests
4
+ beautifulsoup4
5
+