niauX commited on
Commit
9e03f43
·
verified ·
1 Parent(s): c9bc3a5

Publish ThingsLog AI examples Space

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ assets/solutions/agriculture-monitoring.png filter=lfs diff=lfs merge=lfs -text
37
+ assets/solutions/energy-monitoring.png filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ __pycache__/
2
+ .DS_Store
3
+ .env
4
+ .venv/
5
+ venv/
README.md CHANGED
@@ -1,12 +1,38 @@
1
  ---
2
- title: Thingslog Ai Examples
3
- emoji: ⚡
4
- colorFrom: yellow
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 6.13.0
8
  app_file: app.py
9
  pinned: false
 
 
 
 
 
 
 
 
 
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: ThingsLog AI Examples
3
+ emoji: 💧
4
+ colorFrom: blue
5
+ colorTo: green
6
  sdk: gradio
7
+ sdk_version: 6.0.2
8
  app_file: app.py
9
  pinned: false
10
+ license: apache-2.0
11
+ short_description: Build monitoring portals and apps on top of ThingsLog data.
12
+ tags:
13
+ - iot
14
+ - water
15
+ - utilities
16
+ - monitoring
17
+ - codex
18
+ - claude
19
+ - smart-metering
20
  ---
21
 
22
+ # ThingsLog AI Examples
23
+
24
+ This Space helps installers, water-system integrators, utility IT teams, and small communal utilities start their own monitoring and alerting apps on top of ThingsLog.
25
+
26
+ Use it to pick a starter repository, generate an implementation prompt for Codex or Claude, and follow the ThingsLog token flow without exposing credentials in a browser app.
27
+
28
+ ## GitHub Starters
29
+
30
+ - [thingslog-api-starter-kit](https://github.com/ThingsLog/thingslog-api-starter-kit)
31
+ - [thingslog-monitoring-portal-template](https://github.com/ThingsLog/thingslog-monitoring-portal-template)
32
+ - [thingslog-nextjs-monitoring-template](https://github.com/ThingsLog/thingslog-nextjs-monitoring-template)
33
+ - [thingslog-vue-monitoring-template](https://github.com/ThingsLog/thingslog-vue-monitoring-template)
34
+ - [thingslog-node-express-api-template](https://github.com/ThingsLog/thingslog-node-express-api-template)
35
+ - [thingslog-python-fastapi-template](https://github.com/ThingsLog/thingslog-python-fastapi-template)
36
+ - [thingslog-ai-examples](https://github.com/ThingsLog/thingslog-ai-examples)
37
+
38
+ Apps and portals built with ThingsLog APIs should include `Powered by ThingsLog` with a link to [thingslog.com](https://thingslog.com).
__pycache__/app.cpython-312.pyc ADDED
Binary file (10.7 kB). View file
 
app.py ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import textwrap
4
+
5
+ import gradio as gr
6
+
7
+
8
+ GITHUB = "https://github.com/ThingsLog"
9
+ THINGSLOG = "https://thingslog.com"
10
+
11
+ STACKS = {
12
+ "React portal": {
13
+ "repo": "thingslog-monitoring-portal-template",
14
+ "best_for": "A polished single-page monitoring portal for demos, pilots, installers, and customer-facing dashboards.",
15
+ "start": "npm install && npm run dev",
16
+ },
17
+ "Next.js portal": {
18
+ "repo": "thingslog-nextjs-monitoring-template",
19
+ "best_for": "Production-style partner portals with server-side token handling and customer workspaces.",
20
+ "start": "npm install && npm run dev",
21
+ },
22
+ "Vue portal": {
23
+ "repo": "thingslog-vue-monitoring-template",
24
+ "best_for": "Vue teams building lightweight monitoring, alerting, and reporting tools.",
25
+ "start": "npm install && npm run dev",
26
+ },
27
+ "Node API": {
28
+ "repo": "thingslog-node-express-api-template",
29
+ "best_for": "Backend gateway for keeping ThingsLog tokens server-side and exposing partner-specific APIs.",
30
+ "start": "npm install && npm run dev",
31
+ },
32
+ "Python FastAPI": {
33
+ "repo": "thingslog-python-fastapi-template",
34
+ "best_for": "Utility IT teams, automation, reporting jobs, data exports, and integration services.",
35
+ "start": "python -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt && uvicorn app.main:app --reload",
36
+ },
37
+ "API starter kit": {
38
+ "repo": "thingslog-api-starter-kit",
39
+ "best_for": "Learning the ThingsLog REST API, token flow, counters, alarms, device metadata, and Push API integration.",
40
+ "start": "Open the README and run the curl examples from a secure terminal.",
41
+ },
42
+ }
43
+
44
+
45
+ def repo_url(repo: str) -> str:
46
+ return f"{GITHUB}/{repo}"
47
+
48
+
49
+ def build_prompt(stack: str, customer_type: str, solution: str, agent: str) -> str:
50
+ item = STACKS[stack]
51
+ return textwrap.dedent(
52
+ f"""
53
+ You are {agent}, helping build a ThingsLog-powered monitoring product.
54
+
55
+ Target customer:
56
+ {customer_type}
57
+
58
+ Solution focus:
59
+ {solution}
60
+
61
+ Starter repository:
62
+ {repo_url(item["repo"])}
63
+
64
+ Build goal:
65
+ Create a branded monitoring portal or app for installers, water-system integrators,
66
+ utility IT teams, small communal utilities, private customers, farms, buildings, or
67
+ industrial sites that need metering, alerts, and operational visibility.
68
+
69
+ ThingsLog API rules:
70
+ - Keep ThingsLog usernames, passwords, and API tokens server-side.
71
+ - Use the ThingsLog login flow to obtain a short-lived Bearer token.
72
+ - Use the API token endpoint only from trusted backend code when a longer-lived token is required.
73
+ - Never commit .env files, real tokens, customer device IDs, or customer measurements.
74
+ - Add "Powered by ThingsLog" with a link to https://thingslog.com in the app footer or about page.
75
+
76
+ Domain context:
77
+ - Water deployments can use popular water meter brands connected through LoRa, NB-IoT, or wireless M-Bus.
78
+ - ThingsLog can also work with Modbus devices and analog 4-20 mA or 0-3 V sensors.
79
+ - Build for real operational workflows: consumption trends, alarms, pressure/level/flow views,
80
+ leak detection, NRW reduction, pump station checks, tank monitoring, and customer reports.
81
+
82
+ Start command:
83
+ {item["start"]}
84
+
85
+ First tasks:
86
+ 1. Read README.md, AGENTS.md, and CLAUDE.md if present.
87
+ 2. Create a .env file from the example values.
88
+ 3. Add mock data mode for demos, then wire real ThingsLog API calls through the backend.
89
+ 4. Keep the UI practical, clear, and suitable for installers and utility operators.
90
+ """
91
+ ).strip()
92
+
93
+
94
+ def stack_details(stack: str) -> str:
95
+ item = STACKS[stack]
96
+ return f"""
97
+ ### {stack}
98
+
99
+ **Repository:** [{item["repo"]}]({repo_url(item["repo"])})
100
+
101
+ **Best for:** {item["best_for"]}
102
+
103
+ **Start:** `{item["start"]}`
104
+ """
105
+
106
+
107
+ with gr.Blocks(
108
+ title="ThingsLog AI Examples",
109
+ css="""
110
+ :root { --tl-blue: #0b5cab; --tl-green: #2f9e44; --tl-ink: #172033; }
111
+ .tl-hero {
112
+ display: grid;
113
+ grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
114
+ gap: 28px;
115
+ align-items: center;
116
+ padding: 22px 0 8px;
117
+ }
118
+ .tl-hero h1 { color: var(--tl-ink); font-size: 42px; line-height: 1.05; margin: 0 0 12px; }
119
+ .tl-hero p { color: #42526b; font-size: 18px; line-height: 1.55; margin: 0; }
120
+ .tl-logo { max-width: 260px; width: 100%; }
121
+ .tl-card img { border-radius: 8px; width: 100%; height: 180px; object-fit: cover; }
122
+ .tl-links a { margin-right: 14px; white-space: nowrap; }
123
+ footer { visibility: hidden; }
124
+ @media (max-width: 820px) {
125
+ .tl-hero { grid-template-columns: 1fr; }
126
+ .tl-hero h1 { font-size: 34px; }
127
+ }
128
+ """,
129
+ ) as demo:
130
+ gr.HTML(
131
+ """
132
+ <div class="tl-hero">
133
+ <div>
134
+ <h1>Build your monitoring business on ThingsLog</h1>
135
+ <p>
136
+ Starter portals, API examples, and AI prompts for water-meter installers,
137
+ system integrators, utility IT teams, and small communal utilities that want
138
+ their own monitoring, alerting, and reporting apps.
139
+ </p>
140
+ <p class="tl-links" style="margin-top:18px">
141
+ <a href="https://thingslog.com" target="_blank">thingslog.com</a>
142
+ <a href="https://github.com/ThingsLog" target="_blank">GitHub starters</a>
143
+ <a href="https://thingslog.com/thingslog-solutions/intelligent-water/" target="_blank">Water</a>
144
+ <a href="https://thingslog.com/thingslog-solutions/energy-consumption-monitoring/" target="_blank">Energy</a>
145
+ <a href="https://thingslog.com/thingslog-solutions/thingslog-smart-agriculture/" target="_blank">Agriculture</a>
146
+ </p>
147
+ </div>
148
+ <div>
149
+ <img class="tl-logo" src="/file=assets/thingslog-logo.png" alt="ThingsLog logo" />
150
+ </div>
151
+ </div>
152
+ """
153
+ )
154
+
155
+ with gr.Row():
156
+ with gr.Column(scale=1):
157
+ gr.Image("assets/solutions/water-monitoring.jpg", label="Water monitoring", show_download_button=False, show_fullscreen_button=False)
158
+ with gr.Column(scale=1):
159
+ gr.Image("assets/solutions/energy-monitoring.png", label="Energy monitoring", show_download_button=False, show_fullscreen_button=False)
160
+ with gr.Column(scale=1):
161
+ gr.Image("assets/solutions/agriculture-monitoring.png", label="Agriculture monitoring", show_download_button=False, show_fullscreen_button=False)
162
+
163
+ gr.Markdown(
164
+ """
165
+ ## Where ThingsLog Fits
166
+
167
+ ThingsLog helps partners build practical IoT monitoring solutions for water, energy, agriculture,
168
+ buildings, and industrial sites. The strongest fit is small and mid-size communal utilities,
169
+ municipal operators, installers, and integrators that need fast deployment without building a full
170
+ IoT platform from scratch. Larger utilities can also use the examples for pilots, department tools,
171
+ and integrations.
172
+
173
+ For water, ThingsLog supports popular water meter brands connected through LoRa, NB-IoT, or
174
+ wireless M-Bus, plus Modbus devices and analog sensors such as 4-20 mA or 0-3 V pressure, level,
175
+ flow, and environmental sensors.
176
+ """
177
+ )
178
+
179
+ with gr.Row():
180
+ stack = gr.Dropdown(list(STACKS), value="Next.js portal", label="Choose starter")
181
+ agent = gr.Dropdown(["Codex", "Claude"], value="Codex", label="AI agent")
182
+
183
+ customer_type = gr.Textbox(
184
+ label="Target customer",
185
+ value="Small communal water utility or local water-system integrator serving private customers and municipalities",
186
+ )
187
+ solution = gr.Textbox(
188
+ label="Monitoring product idea",
189
+ value="Water consumption dashboard with alarms, leak indicators, meter status, customer reporting, and a Powered by ThingsLog footer",
190
+ )
191
+
192
+ details = gr.Markdown()
193
+ prompt = gr.Textbox(label="Prompt for your AI agent", lines=22, show_copy_button=True)
194
+
195
+ stack.change(stack_details, inputs=stack, outputs=details)
196
+ for field in (stack, customer_type, solution, agent):
197
+ field.change(build_prompt, inputs=[stack, customer_type, solution, agent], outputs=prompt)
198
+
199
+ demo.load(stack_details, inputs=stack, outputs=details)
200
+ demo.load(build_prompt, inputs=[stack, customer_type, solution, agent], outputs=prompt)
201
+
202
+ gr.Markdown(
203
+ """
204
+ ## Token Flow
205
+
206
+ 1. Sign in to the ThingsLog IoT portal with a partner or customer account.
207
+ 2. Exchange credentials for a Bearer token from the ThingsLog login endpoint.
208
+ 3. For trusted backend services, create a named long-term API token with an expiration period.
209
+ 4. Store tokens only in backend environment variables or secret managers.
210
+ 5. Build customer-facing apps through a backend gateway, never by exposing ThingsLog tokens in frontend code.
211
+
212
+ Read the full guide in the [thingslog-ai-examples token document](https://github.com/ThingsLog/thingslog-ai-examples/blob/main/docs/generate-thingslog-api-token.md).
213
+
214
+ **Powered by [ThingsLog](https://thingslog.com).**
215
+ """
216
+ )
217
+
218
+
219
+ if __name__ == "__main__":
220
+ demo.launch()
assets/solutions/agriculture-monitoring.png ADDED

Git LFS Details

  • SHA256: 0ea49f2daaabdf2f688916bd09f47199e6fe71ff43087b7427180480a274c077
  • Pointer size: 131 Bytes
  • Size of remote file: 202 kB
assets/solutions/energy-monitoring.png ADDED

Git LFS Details

  • SHA256: 75ba7ac835e05b749d577ee99ec454bd898bff2ac94d4ab0f64fe27a52d9f157
  • Pointer size: 131 Bytes
  • Size of remote file: 144 kB
assets/solutions/water-monitoring.jpg ADDED
assets/thingslog-logo.png ADDED
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio>=6.0.0