Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,45 +1,41 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Light Rider Quantum Entropy
|
| 3 |
-
emoji: ⚛️
|
| 4 |
-
colorFrom: red
|
| 5 |
-
colorTo: yellow
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 6.30.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
license: apache-2.0
|
| 11 |
-
short_description:
|
| 12 |
-
---
|
| 13 |
-
|
| 14 |
-
# Light Rider Quantum Entropy
|
| 15 |
-
|
| 16 |
-
Draw random bytes from
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
`LR_VERCEL_BYPASS` (only while pointing at a protected preview deployment).
|
| 43 |
-
|
| 44 |
-
Optional variables: `DEMO_PER_VISITOR_DAILY` (default 5), `DEMO_GLOBAL_DAILY`
|
| 45 |
-
(default 200), `LR_PUBLIC_SITE_URL`, `LR_CLOUD_KEYS_URL`.
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Light Rider Quantum Entropy
|
| 3 |
+
emoji: ⚛️
|
| 4 |
+
colorFrom: red
|
| 5 |
+
colorTo: yellow
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 6.30.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
short_description: Quantum random bytes with signed, verifiable receipts
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# Light Rider Quantum Entropy
|
| 15 |
+
|
| 16 |
+
Draw random bytes from a named quantum source: a quantum random number generator or a quantum
|
| 17 |
+
processor. Every draw comes with a receipt, signed by Light Rider, that records which source
|
| 18 |
+
produced the bytes and when. The app checks the signature and shows you the result.
|
| 19 |
+
|
| 20 |
+
It's an alternative entropy source you can verify, not a claim that quantum randomness beats a
|
| 21 |
+
good classical generator. If a source can't serve, the app says so; no other source is used in
|
| 22 |
+
its place.
|
| 23 |
+
|
| 24 |
+
## Use it from your code
|
| 25 |
+
|
| 26 |
+
```bash
|
| 27 |
+
pip install lightrider
|
| 28 |
+
export LR_API_KEY=lr_live_... # your Light Rider API key
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
```python
|
| 32 |
+
import lightrider as lr
|
| 33 |
+
|
| 34 |
+
r = lr.entropy.get(16, source="anu") # 16 bytes from the ANU quantum RNG
|
| 35 |
+
print(r.hex, r.sources, r.request_id)
|
| 36 |
+
assert lr.entropy.verify(r.receipt) # the receipt is genuine
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
Create your API key at [entropy.lightriderinc.com/developers](https://entropy.lightriderinc.com/developers),
|
| 40 |
+
which also documents the HTTP API. The key gives full access to your account, so keep it out of
|
| 41 |
+
public code.
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,21 +1,17 @@
|
|
| 1 |
"""Light Rider Quantum Entropy: Hugging Face Space demo.
|
| 2 |
|
| 3 |
-
Draws
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
| 7 |
-
LR_API_KEY
|
| 8 |
-
LR_ENTROPY_BASE_URL entropy site to call (dev for now)
|
| 9 |
-
LR_VERCEL_BYPASS x-vercel-protection-bypass, sent only when set
|
| 10 |
|
| 11 |
Optional variables:
|
| 12 |
DEMO_PER_VISITOR_DAILY draws per visitor per UTC day (default 5)
|
| 13 |
DEMO_GLOBAL_DAILY draws for the whole Space per UTC day (default 200)
|
| 14 |
-
LR_PUBLIC_SITE_URL public entropy site for links (default production)
|
| 15 |
-
LR_CLOUD_KEYS_URL Light Rider Cloud API Keys page
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
"""
|
| 20 |
|
| 21 |
from __future__ import annotations
|
|
@@ -33,11 +29,10 @@ from lightrider.entropy import api as lre
|
|
| 33 |
MIN_BYTES, MAX_BYTES = 16, 512
|
| 34 |
PER_VISITOR_DAILY = int(os.environ.get("DEMO_PER_VISITOR_DAILY", "5"))
|
| 35 |
GLOBAL_DAILY = int(os.environ.get("DEMO_GLOBAL_DAILY", "200"))
|
| 36 |
-
PUBLIC_SITE =
|
| 37 |
-
CLOUD_KEYS_URL = os.environ.get("LR_CLOUD_KEYS_URL", "https://cloud.lightriderinc.com/settings/keys")
|
| 38 |
BRAND = "#ef3b39"
|
| 39 |
|
| 40 |
-
# Reads LR_API_KEY
|
| 41 |
client = lre.EntropyAPI(max_retries=1, timeout=60)
|
| 42 |
|
| 43 |
|
|
@@ -166,10 +161,10 @@ def _friendly(err: lre.EntropyAPIError, what: str) -> str:
|
|
| 166 |
def _badge(ok: bool) -> str:
|
| 167 |
if ok:
|
| 168 |
return (
|
| 169 |
-
'<div class="lr-badge lr-ok">✔ Verified:
|
| 170 |
-
"
|
| 171 |
)
|
| 172 |
-
return '<div class="lr-badge lr-bad">✘ Not verified: the signature
|
| 173 |
|
| 174 |
|
| 175 |
def generate(mode: str, source_id: str | None, custom_ids: list[str] | None, n_bytes: float, request: gr.Request | None = None):
|
|
@@ -229,42 +224,37 @@ def toggle_mode(mode: str):
|
|
| 229 |
INTRO = f"""
|
| 230 |
# Light Rider Quantum Entropy
|
| 231 |
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
and nothing here is generated locally.
|
| 239 |
|
| 240 |
-
<small>
|
| 241 |
"""
|
| 242 |
|
| 243 |
CODE = f"""
|
| 244 |
### Draw entropy from your own code
|
| 245 |
|
| 246 |
```bash
|
| 247 |
-
pip install lightrider
|
| 248 |
-
export LR_API_KEY=lr_live_...
|
| 249 |
```
|
| 250 |
|
| 251 |
```python
|
| 252 |
import lightrider as lr
|
| 253 |
|
| 254 |
-
r = lr.entropy.get(16, source="anu")
|
| 255 |
-
print(r.hex, r.
|
| 256 |
-
assert lr.entropy.verify(r.receipt)
|
| 257 |
-
seed = lr.entropy.seed(64) # int seed for numpy / torch
|
| 258 |
```
|
| 259 |
|
| 260 |
-
- **
|
| 261 |
-
|
| 262 |
-
- **
|
| 263 |
-
|
| 264 |
-
- **
|
| 265 |
-
- **Price:** 1 token (one Light Rider credit, $0.01) per 256 bytes. Single source or a custom pool of 2 to 8
|
| 266 |
-
sources, up to 4096 bytes per call.
|
| 267 |
-
- **Strict:** if the source can't serve, you get `SourceEmptyError`, never a substitute.
|
| 268 |
"""
|
| 269 |
|
| 270 |
CSS = f"""
|
|
|
|
| 1 |
"""Light Rider Quantum Entropy: Hugging Face Space demo.
|
| 2 |
|
| 3 |
+
Draws random bytes from a named quantum source with the lightrider SDK and
|
| 4 |
+
shows the signed receipt, verified with Ed25519.
|
| 5 |
|
| 6 |
+
Secret:
|
| 7 |
+
LR_API_KEY Light Rider API key that pays for the demo's draws
|
|
|
|
|
|
|
| 8 |
|
| 9 |
Optional variables:
|
| 10 |
DEMO_PER_VISITOR_DAILY draws per visitor per UTC day (default 5)
|
| 11 |
DEMO_GLOBAL_DAILY draws for the whole Space per UTC day (default 200)
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
If a source can't serve, the visitor sees why. No other source is used in its
|
| 14 |
+
place, and this app never generates randomness itself.
|
| 15 |
"""
|
| 16 |
|
| 17 |
from __future__ import annotations
|
|
|
|
| 29 |
MIN_BYTES, MAX_BYTES = 16, 512
|
| 30 |
PER_VISITOR_DAILY = int(os.environ.get("DEMO_PER_VISITOR_DAILY", "5"))
|
| 31 |
GLOBAL_DAILY = int(os.environ.get("DEMO_GLOBAL_DAILY", "200"))
|
| 32 |
+
PUBLIC_SITE = "https://entropy.lightriderinc.com"
|
|
|
|
| 33 |
BRAND = "#ef3b39"
|
| 34 |
|
| 35 |
+
# Reads LR_API_KEY from the environment.
|
| 36 |
client = lre.EntropyAPI(max_retries=1, timeout=60)
|
| 37 |
|
| 38 |
|
|
|
|
| 161 |
def _badge(ok: bool) -> str:
|
| 162 |
if ok:
|
| 163 |
return (
|
| 164 |
+
'<div class="lr-badge lr-ok">✔ Verified: this receipt is signed by Light Rider and hasn\'t been '
|
| 165 |
+
"changed.</div>"
|
| 166 |
)
|
| 167 |
+
return '<div class="lr-badge lr-bad">✘ Not verified: the receipt\'s signature didn\'t match Light Rider\'s public key.</div>'
|
| 168 |
|
| 169 |
|
| 170 |
def generate(mode: str, source_id: str | None, custom_ids: list[str] | None, n_bytes: float, request: gr.Request | None = None):
|
|
|
|
| 224 |
INTRO = f"""
|
| 225 |
# Light Rider Quantum Entropy
|
| 226 |
|
| 227 |
+
Draw random bytes from a named quantum source: a quantum random number generator or a quantum processor.
|
| 228 |
+
Every draw comes with a receipt, signed by Light Rider, that records which source produced the bytes and when.
|
| 229 |
+
The app checks the signature for you.
|
| 230 |
|
| 231 |
+
It's an alternative entropy source you can verify, not a claim that quantum randomness beats a good classical
|
| 232 |
+
generator. If a source can't serve, you'll see why; no other source is used in its place.
|
|
|
|
| 233 |
|
| 234 |
+
<small>Up to {PER_VISITOR_DAILY} draws per visitor per day. Your bytes are shown once and never stored.</small>
|
| 235 |
"""
|
| 236 |
|
| 237 |
CODE = f"""
|
| 238 |
### Draw entropy from your own code
|
| 239 |
|
| 240 |
```bash
|
| 241 |
+
pip install lightrider
|
| 242 |
+
export LR_API_KEY=lr_live_... # your Light Rider API key
|
| 243 |
```
|
| 244 |
|
| 245 |
```python
|
| 246 |
import lightrider as lr
|
| 247 |
|
| 248 |
+
r = lr.entropy.get(16, source="anu") # 16 bytes from the ANU quantum RNG
|
| 249 |
+
print(r.hex, r.sources, r.request_id)
|
| 250 |
+
assert lr.entropy.verify(r.receipt) # the receipt is genuine
|
|
|
|
| 251 |
```
|
| 252 |
|
| 253 |
+
- **API key:** create one at [{PUBLIC_SITE}/developers]({PUBLIC_SITE}/developers), which also documents the
|
| 254 |
+
HTTP API. The key gives full access to your account, so keep it out of public code.
|
| 255 |
+
- **Sources:** use a short name (`anu`, `cisco`, `qispace`, `rigetti`, `iqm`, `iqm-qec`) or the full id.
|
| 256 |
+
`lr.entropy.sources()` lists what's available right now. `sources=["anu", "cisco"]` blends 2 to 8 sources.
|
| 257 |
+
- **Price:** 1 credit ($0.01) per 256 bytes, up to 4096 bytes per call. A draw that fails isn't charged.
|
|
|
|
|
|
|
|
|
|
| 258 |
"""
|
| 259 |
|
| 260 |
CSS = f"""
|