dmontgomery40 commited on
Commit
ee600ac
·
verified ·
1 Parent(s): 06bafd8

Sync from GitHub via hub-sync

Browse files
Dockerfile CHANGED
@@ -7,7 +7,8 @@ RUN npm run build
7
 
8
  FROM python:3.12-slim
9
  WORKDIR /app
10
- RUN pip install --no-cache-dir torch==2.14.0 --index-url https://download.pytorch.org/whl/cpu
 
11
  COPY pyproject.toml README.md LICENSE ./
12
  COPY plastic/ ./plastic/
13
  RUN pip install --no-cache-dir '.[pretrained]'
@@ -17,6 +18,6 @@ COPY text/ ./text/
17
  COPY --from=frontend /build/dist ./dashboard/dist
18
  RUN useradd --uid 1000 --create-home demo
19
  USER demo
20
- ENV PYTHONUNBUFFERED=1 OMP_NUM_THREADS=2 MKL_NUM_THREADS=2 PORT=7860 QWEN_CHECKPOINT=/opt/qwen
21
  EXPOSE 7860
22
  CMD ["python", "-m", "deploy.huggingface.app"]
 
7
 
8
  FROM python:3.12-slim
9
  WORKDIR /app
10
+ # the default PyPI wheel carries CUDA and falls back to CPU where no GPU exists
11
+ RUN pip install --no-cache-dir torch==2.14.0
12
  COPY pyproject.toml README.md LICENSE ./
13
  COPY plastic/ ./plastic/
14
  RUN pip install --no-cache-dir '.[pretrained]'
 
18
  COPY --from=frontend /build/dist ./dashboard/dist
19
  RUN useradd --uid 1000 --create-home demo
20
  USER demo
21
+ ENV PYTHONUNBUFFERED=1 PORT=7860 QWEN_CHECKPOINT=/opt/qwen
22
  EXPOSE 7860
23
  CMD ["python", "-m", "deploy.huggingface.app"]
deploy/huggingface/Dockerfile CHANGED
@@ -7,7 +7,8 @@ RUN npm run build
7
 
8
  FROM python:3.12-slim
9
  WORKDIR /app
10
- RUN pip install --no-cache-dir torch==2.14.0 --index-url https://download.pytorch.org/whl/cpu
 
11
  COPY pyproject.toml README.md LICENSE ./
12
  COPY plastic/ ./plastic/
13
  RUN pip install --no-cache-dir '.[pretrained]'
@@ -17,6 +18,6 @@ COPY text/ ./text/
17
  COPY --from=frontend /build/dist ./dashboard/dist
18
  RUN useradd --uid 1000 --create-home demo
19
  USER demo
20
- ENV PYTHONUNBUFFERED=1 OMP_NUM_THREADS=2 MKL_NUM_THREADS=2 PORT=7860 QWEN_CHECKPOINT=/opt/qwen
21
  EXPOSE 7860
22
  CMD ["python", "-m", "deploy.huggingface.app"]
 
7
 
8
  FROM python:3.12-slim
9
  WORKDIR /app
10
+ # the default PyPI wheel carries CUDA and falls back to CPU where no GPU exists
11
+ RUN pip install --no-cache-dir torch==2.14.0
12
  COPY pyproject.toml README.md LICENSE ./
13
  COPY plastic/ ./plastic/
14
  RUN pip install --no-cache-dir '.[pretrained]'
 
18
  COPY --from=frontend /build/dist ./dashboard/dist
19
  RUN useradd --uid 1000 --create-home demo
20
  USER demo
21
+ ENV PYTHONUNBUFFERED=1 PORT=7860 QWEN_CHECKPOINT=/opt/qwen
22
  EXPOSE 7860
23
  CMD ["python", "-m", "deploy.huggingface.app"]
deploy/huggingface/app.py CHANGED
@@ -49,9 +49,10 @@ PUBLIC_CAPABILITIES = {'create_session': False, 'fork': False, 'reset': True, 'd
49
 
50
  class PublicDemoGate:
51
  """Expose the fixed text playground without changing the local research API."""
52
- def __init__(self, app, store=None):
53
  self.app = app
54
  self.store = store
 
55
  self.busy = asyncio.Lock()
56
 
57
  async def __call__(self, scope, receive, send):
@@ -79,7 +80,7 @@ class PublicDemoGate:
79
  elif path == '/api/sessions':
80
  result = sessions
81
  else:
82
- result = {'ok': True, 'artifacts_root': self.store.root, 'device': 'cpu',
83
  'n_models': len(models), 'n_sessions': len(sessions),
84
  'capabilities': dict(PUBLIC_CAPABILITIES), 'public': True}
85
  return await JSONResponse(sanitize(result))(scope, receive, send)
@@ -132,10 +133,15 @@ Sessions are <strong>public and shared</strong>. Do not enter private informatio
132
  </aside>'''
133
 
134
 
135
- def create_demo(artifacts_root: str, dashboard_dist: str):
 
 
 
 
 
136
  from plastic.api.app import create_app
137
  # the shared demo lets visitors chat and reset only; the UI renders exactly these capabilities
138
- app = create_app(artifacts_root, device='cpu', public=True, capabilities=PUBLIC_CAPABILITIES)
139
  dist = Path(dashboard_dist)
140
  page, count = re.subn(r'(<body\b[^>]*>)', lambda match: match[0][:-1] + ' data-public-demo="true">' + NOTICE,
141
  (dist / 'index.html').read_text(), count=1, flags=re.IGNORECASE)
@@ -147,7 +153,7 @@ def create_demo(artifacts_root: str, dashboard_dist: str):
147
  def index():
148
  return page
149
 
150
- return PublicDemoGate(app, app.state.store)
151
 
152
 
153
  def main():
@@ -155,11 +161,13 @@ def main():
155
  import uvicorn
156
  from deploy.huggingface.prepare import prepare_store
157
  from deploy.huggingface.pretrained import prepare_pretrained_sessions
158
- torch.set_num_threads(2)
 
 
159
  root = os.environ.get('ARTIFACTS_ROOT', '/tmp/plastic-demo')
160
  store = prepare_store(Path('.'), Path(root), seed_sessions=False)
161
  prepare_pretrained_sessions(store, Path(os.environ.get('QWEN_CHECKPOINT', '/opt/qwen')))
162
- app = create_demo(root, os.environ.get('DASHBOARD_DIST', 'dashboard/dist'))
163
  uvicorn.run(app, host='0.0.0.0', port=int(os.environ.get('PORT', '7860')), access_log=False)
164
 
165
 
 
49
 
50
  class PublicDemoGate:
51
  """Expose the fixed text playground without changing the local research API."""
52
+ def __init__(self, app, store=None, device='cpu'):
53
  self.app = app
54
  self.store = store
55
+ self.device = device
56
  self.busy = asyncio.Lock()
57
 
58
  async def __call__(self, scope, receive, send):
 
80
  elif path == '/api/sessions':
81
  result = sessions
82
  else:
83
+ result = {'ok': True, 'artifacts_root': self.store.root, 'device': self.device,
84
  'n_models': len(models), 'n_sessions': len(sessions),
85
  'capabilities': dict(PUBLIC_CAPABILITIES), 'public': True}
86
  return await JSONResponse(sanitize(result))(scope, receive, send)
 
133
  </aside>'''
134
 
135
 
136
+ def pick_device() -> str:
137
+ import torch
138
+ return 'cuda' if torch.cuda.is_available() else 'cpu'
139
+
140
+
141
+ def create_demo(artifacts_root: str, dashboard_dist: str, device: str = 'cpu'):
142
  from plastic.api.app import create_app
143
  # the shared demo lets visitors chat and reset only; the UI renders exactly these capabilities
144
+ app = create_app(artifacts_root, device=device, public=True, capabilities=PUBLIC_CAPABILITIES)
145
  dist = Path(dashboard_dist)
146
  page, count = re.subn(r'(<body\b[^>]*>)', lambda match: match[0][:-1] + ' data-public-demo="true">' + NOTICE,
147
  (dist / 'index.html').read_text(), count=1, flags=re.IGNORECASE)
 
153
  def index():
154
  return page
155
 
156
+ return PublicDemoGate(app, app.state.store, device)
157
 
158
 
159
  def main():
 
161
  import uvicorn
162
  from deploy.huggingface.prepare import prepare_store
163
  from deploy.huggingface.pretrained import prepare_pretrained_sessions
164
+ torch.set_num_threads(max(1, min(8, os.cpu_count() or 2)))
165
+ device = pick_device()
166
+ print(f'[demo] device {device}, torch {torch.__version__}, threads {torch.get_num_threads()}', flush=True)
167
  root = os.environ.get('ARTIFACTS_ROOT', '/tmp/plastic-demo')
168
  store = prepare_store(Path('.'), Path(root), seed_sessions=False)
169
  prepare_pretrained_sessions(store, Path(os.environ.get('QWEN_CHECKPOINT', '/opt/qwen')))
170
+ app = create_demo(root, os.environ.get('DASHBOARD_DIST', 'dashboard/dist'), device)
171
  uvicorn.run(app, host='0.0.0.0', port=int(os.environ.get('PORT', '7860')), access_log=False)
172
 
173
 
source_snapshot.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "github_repository": "DMontgomery40/plastic",
3
- "github_commit": "1230aa0b42683a57f11e239e40161ae10ba2774c",
4
- "preserved_hf_revision": "ae7fcf1085680526e9c105c4556c46ea4b9dbb38",
5
  "repo_type": "space"
6
  }
 
1
  {
2
  "github_repository": "DMontgomery40/plastic",
3
+ "github_commit": "46d0a06830a01315a1b201feca14ca2f47217768",
4
+ "preserved_hf_revision": "06bafd8484fb3b678e2f8d9a46b539ec8015feab",
5
  "repo_type": "space"
6
  }