Spaces:
Sleeping
Sleeping
Use normal Hugging Face Space URLs for copied poll links
Browse files
README.md
CHANGED
|
@@ -14,7 +14,7 @@ pinned: false
|
|
| 14 |
|
| 15 |
# HuggingPolls
|
| 16 |
|
| 17 |
-
Sign in with Hugging Face to create polls, share `https://
|
| 18 |
|
| 19 |
**HuggingPolls is an independent community project. It is not affiliated with, endorsed by, or sponsored by Hugging Face.**
|
| 20 |
|
|
@@ -37,4 +37,4 @@ Install `requirements.txt`, then run `uvicorn app:app --host 0.0.0.0 --port 7860
|
|
| 37 |
|
| 38 |
Each browser receives a signed anonymous identifier. Signed-in votes are also associated with a hashed HF identity. Results are available to the creator at any time and to voters after they vote, enforced on the server. CSV exports and management controls are restricted to the creator. No access tokens, email addresses, or raw account IDs of voters are saved. Creators' account IDs and usernames are saved for ownership. Anyone with the link can see the question and options. Guest repeat-vote prevention is browser-based: clearing cookies or using a different browser can bypass it. These are casual polls, not verified elections.
|
| 39 |
|
| 40 |
-
Open the app directly at its `hf.space` URL for sign-in: embedded browsers can block the cookies required by OAuth.
|
|
|
|
| 14 |
|
| 15 |
# HuggingPolls
|
| 16 |
|
| 17 |
+
Sign in with Hugging Face to create polls, share `https://huggingface.co/spaces/Banaxi-Tech/HuggingPolls#POLL_ID`, and manage results. Guests and signed-in users can vote. Creators can see totals and percentages, export CSV, close/reopen, and delete their polls. Uses the supplied Judge Huggy logo.
|
| 18 |
|
| 19 |
**HuggingPolls is an independent community project. It is not affiliated with, endorsed by, or sponsored by Hugging Face.**
|
| 20 |
|
|
|
|
| 37 |
|
| 38 |
Each browser receives a signed anonymous identifier. Signed-in votes are also associated with a hashed HF identity. Results are available to the creator at any time and to voters after they vote, enforced on the server. CSV exports and management controls are restricted to the creator. No access tokens, email addresses, or raw account IDs of voters are saved. Creators' account IDs and usernames are saved for ownership. Anyone with the link can see the question and options. Guest repeat-vote prevention is browser-based: clearing cookies or using a different browser can bypass it. These are casual polls, not verified elections.
|
| 39 |
|
| 40 |
+
Open the app directly at its `hf.space` URL for sign-in: embedded browsers can block the cookies required by OAuth. Copied poll links use the normal `huggingface.co/spaces/OWNER/SPACE#POLL_ID` URL.
|
app.py
CHANGED
|
@@ -28,6 +28,8 @@ if not SECRET:
|
|
| 28 |
SECRET = secrets.token_hex(32)
|
| 29 |
HOST = os.getenv('SPACE_HOST')
|
| 30 |
BASE = f'https://{HOST}' if HOST else os.getenv('BASE_URL', 'http://localhost:7860')
|
|
|
|
|
|
|
| 31 |
LOCK = threading.RLock()
|
| 32 |
api = HfApi(token=TOKEN) if REPO else None
|
| 33 |
path = DATA / 'polls.json'
|
|
@@ -187,7 +189,7 @@ def create_poll(body: NewPoll, request: Request):
|
|
| 187 |
new['polls'][poll_id] = dict(id=poll_id, question=question, description=body.description.strip(), options=options,
|
| 188 |
owner_id=identity['id'], owner=identity['name'], created_at=now(), closed=False, votes=[])
|
| 189 |
save(new)
|
| 190 |
-
return {'id': poll_id, 'url':
|
| 191 |
|
| 192 |
|
| 193 |
@app.get('/api/polls')
|
|
@@ -207,7 +209,7 @@ def poll_detail(poll_id: str, request: Request):
|
|
| 207 |
vote = next((v for v in p['votes'] if set(v['keys']) & set(keys)), None)
|
| 208 |
return {**{k: p[k] for k in ['id', 'question', 'description', 'options', 'owner', 'created_at', 'closed']},
|
| 209 |
'is_owner': owner, 'voted': vote is not None, 'choice': vote['choice'] if vote else None,
|
| 210 |
-
'url':
|
| 211 |
'results': [sum(v['choice'] == i for v in p['votes']) for i in range(len(p['options']))] if owner or vote is not None else None}
|
| 212 |
|
| 213 |
|
|
|
|
| 28 |
SECRET = secrets.token_hex(32)
|
| 29 |
HOST = os.getenv('SPACE_HOST')
|
| 30 |
BASE = f'https://{HOST}' if HOST else os.getenv('BASE_URL', 'http://localhost:7860')
|
| 31 |
+
SPACE_ID = os.getenv('SPACE_ID', 'Banaxi-Tech/HuggingPolls')
|
| 32 |
+
SHARE_BASE = f'https://huggingface.co/spaces/{SPACE_ID}' if HOST else BASE
|
| 33 |
LOCK = threading.RLock()
|
| 34 |
api = HfApi(token=TOKEN) if REPO else None
|
| 35 |
path = DATA / 'polls.json'
|
|
|
|
| 189 |
new['polls'][poll_id] = dict(id=poll_id, question=question, description=body.description.strip(), options=options,
|
| 190 |
owner_id=identity['id'], owner=identity['name'], created_at=now(), closed=False, votes=[])
|
| 191 |
save(new)
|
| 192 |
+
return {'id': poll_id, 'url': SHARE_BASE + '#' + poll_id}
|
| 193 |
|
| 194 |
|
| 195 |
@app.get('/api/polls')
|
|
|
|
| 209 |
vote = next((v for v in p['votes'] if set(v['keys']) & set(keys)), None)
|
| 210 |
return {**{k: p[k] for k in ['id', 'question', 'description', 'options', 'owner', 'created_at', 'closed']},
|
| 211 |
'is_owner': owner, 'voted': vote is not None, 'choice': vote['choice'] if vote else None,
|
| 212 |
+
'url': SHARE_BASE + '#' + p['id'],
|
| 213 |
'results': [sum(v['choice'] == i for v in p['votes']) for i in range(len(p['options']))] if owner or vote is not None else None}
|
| 214 |
|
| 215 |
|