thecollabagepatch commited on
Commit
dcfd5bb
Β·
1 Parent(s): e31f469

cleaning up app.py

Browse files
Files changed (3) hide show
  1. Dockerfile +2 -0
  2. app.py +12 -71
  3. documentation.html +69 -0
Dockerfile CHANGED
@@ -142,6 +142,8 @@ COPY --chown=appuser:appuser app.py /home/appuser/app/app.py
142
  COPY --chown=appuser:appuser utils.py /home/appuser/app/utils.py
143
  COPY --chown=appuser:appuser jam_worker.py /home/appuser/app/jam_worker.py
144
 
 
 
145
  USER appuser
146
 
147
  EXPOSE 7860
 
142
  COPY --chown=appuser:appuser utils.py /home/appuser/app/utils.py
143
  COPY --chown=appuser:appuser jam_worker.py /home/appuser/app/jam_worker.py
144
 
145
+ COPY --chown=appuser:appuser documentation.html /home/appuser/app/documentation.html
146
+
147
  USER appuser
148
 
149
  EXPOSE 7860
app.py CHANGED
@@ -2102,75 +2102,16 @@ def ping():
2102
  @app.get("/", response_class=Response)
2103
  def read_root():
2104
  """Root endpoint that explains what this API does"""
2105
- html_content = """
2106
- <!DOCTYPE html>
2107
- <html>
2108
- <head>
2109
- <meta charset="utf-8">
2110
- <title>MagentaRT Research API</title>
2111
- <style>
2112
- body { font-family: Arial, sans-serif; max-width: 860px; margin: 48px auto; padding: 0 20px; color:#111; }
2113
- code, pre { background:#f6f8fa; border:1px solid #eaecef; border-radius:6px; padding:2px 6px; }
2114
- pre { padding:12px; overflow:auto; }
2115
- .muted { color:#555; }
2116
- ul { line-height: 1.8; }
2117
- </style>
2118
- </head>
2119
- <body>
2120
- <h1>🎡 MagentaRT Research API</h1>
2121
- <p class="muted"><strong>Purpose:</strong> AI music generation for iOS/web app research using Google's MagentaRT.</p>
2122
-
2123
- <h2>Available Endpoints</h2>
2124
- <ul>
2125
- <li><code>POST /generate</code> – Generate 4–8 bars of music (HTTP, bar-aligned)</li>
2126
- <li><code>POST /jam/start</code> – Start continuous jamming (HTTP)</li>
2127
- <li><code>GET /jam/next</code> – Get next chunk (HTTP)</li>
2128
- <li><code>POST /jam/consume</code> – Confirm a chunk as consumed (HTTP)</li>
2129
- <li><code>POST /jam/stop</code> – End session (HTTP)</li>
2130
- <li><code>WEBSOCKET /ws/jam</code> – Realtime streaming (<code>mode="rt"</code>)</li>
2131
- <li><code>GET /docs</code> – API documentation (Gradio)</li>
2132
- </ul>
2133
-
2134
- <h2>WebSocket Quick Start (rt mode)</h2>
2135
- <p>Connect to <code>wss://&lt;your-space&gt;/ws/jam</code> and send:</p>
2136
- <pre>{
2137
- "type": "start",
2138
- "mode": "rt",
2139
- "binary_audio": false,
2140
- "params": {
2141
- "styles": "warmup",
2142
- "temperature": 1.1,
2143
- "topk": 40,
2144
- "guidance_weight": 1.1,
2145
- "pace": "realtime", // or "asap" to bootstrap quickly
2146
- "max_decode_frames": 50 // default ~2.0s; try 36–45 on smaller GPUs
2147
- }
2148
- }</pre>
2149
- <p>Update parameters live:</p>
2150
- <pre>{
2151
- "type": "update",
2152
- "styles": "jazz, hiphop",
2153
- "style_weights": "1.0,0.8",
2154
- "temperature": 1.2,
2155
- "topk": 64,
2156
- "guidance_weight": 1.0,
2157
- "pace": "realtime",
2158
- "max_decode_frames": 40
2159
- }</pre>
2160
- <p>Stop:</p>
2161
- <pre>{"type":"stop"}</pre>
2162
-
2163
- <h2>Notes</h2>
2164
- <ul>
2165
- <li>Audio: 48 kHz stereo, ~2.0 s chunks by default with ~40 ms crossfade.</li>
2166
- <li>L40S 48GB: faster than realtime β†’ prefer <code>pace: "realtime"</code>.</li>
2167
- <li>L4 24GB: slightly under realtime even with pre-roll and tuning.</li>
2168
- <li>For sustained realtime, target ~40 GB VRAM per active stream (e.g., A100 40GB or β‰ˆ35–40 GB MIG slice).</li>
2169
- </ul>
2170
-
2171
- <p class="muted"><strong>Licensing:</strong> Uses MagentaRT (Apache 2.0 + CC-BY 4.0). Users are responsible for outputs.</p>
2172
- <p>See <a href="/docs">/docs</a> for full API details and client examples.</p>
2173
- </body>
2174
- </html>
2175
- """
2176
  return Response(content=html_content, media_type="text/html")
 
2102
  @app.get("/", response_class=Response)
2103
  def read_root():
2104
  """Root endpoint that explains what this API does"""
2105
+ try:
2106
+ html_file = Path(__file__).parent / "documentation.html"
2107
+ html_content = html_file.read_text(encoding='utf-8')
2108
+ except FileNotFoundError:
2109
+ # Fallback if file is missing
2110
+ html_content = """
2111
+ <!DOCTYPE html>
2112
+ <html><body>
2113
+ <h1>MagentaRT Research API</h1>
2114
+ <p>Documentation file not found. Please check documentation.html</p>
2115
+ </body></html>
2116
+ """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2117
  return Response(content=html_content, media_type="text/html")
documentation.html ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>MagentaRT Research API</title>
6
+ <style>
7
+ body { font-family: Arial, sans-serif; max-width: 860px; margin: 48px auto; padding: 0 20px; color:#111; }
8
+ code, pre { background:#f6f8fa; border:1px solid #eaecef; border-radius:6px; padding:2px 6px; }
9
+ pre { padding:12px; overflow:auto; }
10
+ .muted { color:#555; }
11
+ ul { line-height: 1.8; }
12
+ </style>
13
+ </head>
14
+ <body>
15
+ <h1>🎡 MagentaRT Research API</h1>
16
+ <p class="muted"><strong>Purpose:</strong> AI music generation for iOS/web app research using Google's MagentaRT.</p>
17
+
18
+ <h2>Available Endpoints</h2>
19
+ <ul>
20
+ <li><code>POST /generate</code> – Generate 4–8 bars of music (HTTP, bar-aligned)</li>
21
+ <li><code>POST /jam/start</code> – Start continuous jamming (HTTP)</li>
22
+ <li><code>GET /jam/next</code> – Get next chunk (HTTP)</li>
23
+ <li><code>POST /jam/consume</code> – Confirm a chunk as consumed (HTTP)</li>
24
+ <li><code>POST /jam/stop</code> – End session (HTTP)</li>
25
+ <li><code>WEBSOCKET /ws/jam</code> – Realtime streaming (<code>mode="rt"</code>)</li>
26
+ <li><code>GET /docs</code> – API documentation (Gradio)</li>
27
+ </ul>
28
+
29
+ <h2>WebSocket Quick Start (rt mode)</h2>
30
+ <p>Connect to <code>wss://&lt;your-space&gt;/ws/jam</code> and send:</p>
31
+ <pre>{
32
+ "type": "start",
33
+ "mode": "rt",
34
+ "binary_audio": false,
35
+ "params": {
36
+ "styles": "warmup",
37
+ "temperature": 1.1,
38
+ "topk": 40,
39
+ "guidance_weight": 1.1,
40
+ "pace": "realtime", // or "asap" to bootstrap quickly
41
+ "max_decode_frames": 50 // default ~2.0s; try 36–45 on smaller GPUs
42
+ }
43
+ }</pre>
44
+ <p>Update parameters live:</p>
45
+ <pre>{
46
+ "type": "update",
47
+ "styles": "jazz, hiphop",
48
+ "style_weights": "1.0,0.8",
49
+ "temperature": 1.2,
50
+ "topk": 64,
51
+ "guidance_weight": 1.0,
52
+ "pace": "realtime",
53
+ "max_decode_frames": 40
54
+ }</pre>
55
+ <p>Stop:</p>
56
+ <pre>{"type":"stop"}</pre>
57
+
58
+ <h2>Notes</h2>
59
+ <ul>
60
+ <li>Audio: 48 kHz stereo, ~2.0 s chunks by default with ~40 ms crossfade.</li>
61
+ <li>L40S 48GB: faster than realtime β†’ prefer <code>pace: "realtime"</code>.</li>
62
+ <li>L4 24GB: slightly under realtime even with pre-roll and tuning.</li>
63
+ <li>For sustained realtime, target ~40 GB VRAM per active stream (e.g., A100 40GB or β‰ˆ35–40 GB MIG slice).</li>
64
+ </ul>
65
+
66
+ <p class="muted"><strong>Licensing:</strong> Uses MagentaRT (Apache 2.0 + CC-BY 4.0). Users are responsible for outputs.</p>
67
+ <p>See <a href="/docs">/docs</a> for full API details and client examples.</p>
68
+ </body>
69
+ </html>