lucataco commited on
Commit
2dc30e3
·
verified ·
1 Parent(s): 08c684a

Replace template with Replicate Inference Provider examples

Browse files
Files changed (2) hide show
  1. index.html +211 -11
  2. style.css +129 -17
index.html CHANGED
@@ -1,19 +1,219 @@
1
  <!doctype html>
2
- <html>
3
  <head>
4
  <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
 
7
  <link rel="stylesheet" href="style.css" />
8
  </head>
9
  <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  </body>
19
  </html>
 
1
  <!doctype html>
2
+ <html lang="en">
3
  <head>
4
  <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Replicate Inference Provider Examples</title>
7
+ <meta name="description" content="Copy-paste examples for running image, video, speech, and audio models on Replicate through Hugging Face Inference Providers." />
8
  <link rel="stylesheet" href="style.css" />
9
  </head>
10
  <body>
11
+ <main>
12
+ <header>
13
+ <h1>Run models on Replicate from Hugging Face</h1>
14
+ <p class="lede">
15
+ Use Replicate as an Inference Provider with the standard Hugging Face clients. Just your
16
+ <code>HF_TOKEN</code> and <code>provider="replicate"</code>, no separate integration needed.
17
+ </p>
18
+ <nav class="links">
19
+ <a href="https://huggingface.co/docs/inference-providers/providers/replicate" target="_blank" rel="noopener">Provider docs</a>
20
+ <a href="https://huggingface.co/collections/replicate/run-with-replicate-6a04d0792d027edbf66c7155" target="_blank" rel="noopener">Featured models</a>
21
+ <a href="https://huggingface.co/models?inference_provider=replicate&amp;sort=trending" target="_blank" rel="noopener">All Replicate-powered models</a>
22
+ <a href="https://replicate.com" target="_blank" rel="noopener">replicate.com</a>
23
+ </nav>
24
+ </header>
25
+
26
+ <section>
27
+ <h2>Setup</h2>
28
+ <div class="tabs" data-group="setup">
29
+ <button class="tab active" data-lang="python">Python</button>
30
+ <button class="tab" data-lang="js">JavaScript</button>
31
+ </div>
32
+ <pre data-group="setup" data-lang="python"><code>pip install -U huggingface_hub pillow
33
+ export HF_TOKEN=hf_...</code></pre>
34
+ <pre data-group="setup" data-lang="js" hidden><code>npm install @huggingface/inference
35
+ export HF_TOKEN=hf_...</code></pre>
36
+ <p class="note">
37
+ Create a token at <a href="https://huggingface.co/settings/tokens" target="_blank" rel="noopener">huggingface.co/settings/tokens</a>
38
+ with the "Make calls to Inference Providers" permission.
39
+ </p>
40
+ </section>
41
+
42
+ <section>
43
+ <h2>Text to image</h2>
44
+ <p class="model">Model: <a href="https://huggingface.co/Tongyi-MAI/Z-Image-Turbo" target="_blank" rel="noopener">Tongyi-MAI/Z-Image-Turbo</a>. Also try <code>black-forest-labs/FLUX.1-dev</code> or <code>Qwen/Qwen-Image</code>.</p>
45
+ <div class="tabs" data-group="t2i">
46
+ <button class="tab active" data-lang="python">Python</button>
47
+ <button class="tab" data-lang="js">JavaScript</button>
48
+ </div>
49
+ <pre data-group="t2i" data-lang="python"><code>import os
50
+ from huggingface_hub import InferenceClient
51
+
52
+ client = InferenceClient(provider="replicate", api_key=os.environ["HF_TOKEN"])
53
+
54
+ image = client.text_to_image(
55
+ "A cinematic photo of an astronaut riding a horse",
56
+ model="Tongyi-MAI/Z-Image-Turbo",
57
+ )
58
+ image.save("astronaut.png")</code></pre>
59
+ <pre data-group="t2i" data-lang="js" hidden><code>import { InferenceClient } from "@huggingface/inference";
60
+ import { writeFile } from "node:fs/promises";
61
+
62
+ const client = new InferenceClient(process.env.HF_TOKEN);
63
+
64
+ const image = await client.textToImage({
65
+ provider: "replicate",
66
+ model: "Tongyi-MAI/Z-Image-Turbo",
67
+ inputs: "A cinematic photo of an astronaut riding a horse",
68
+ });
69
+ await writeFile("astronaut.png", Buffer.from(await image.arrayBuffer()));</code></pre>
70
+ </section>
71
+
72
+ <section>
73
+ <h2>Image editing (image to image)</h2>
74
+ <p class="model">Model: <a href="https://huggingface.co/black-forest-labs/FLUX.1-Kontext-dev" target="_blank" rel="noopener">black-forest-labs/FLUX.1-Kontext-dev</a>. Also try <code>Qwen/Qwen-Image-Edit</code> or <code>black-forest-labs/FLUX.2-dev</code>.</p>
75
+ <div class="tabs" data-group="i2i">
76
+ <button class="tab active" data-lang="python">Python</button>
77
+ <button class="tab" data-lang="js">JavaScript</button>
78
+ </div>
79
+ <pre data-group="i2i" data-lang="python"><code>import os
80
+ from huggingface_hub import InferenceClient
81
+
82
+ client = InferenceClient(provider="replicate", api_key=os.environ["HF_TOKEN"])
83
+
84
+ image = client.image_to_image(
85
+ "cat.png",
86
+ prompt="Turn the cat into a tiger",
87
+ model="black-forest-labs/FLUX.1-Kontext-dev",
88
+ )
89
+ image.save("tiger.png")</code></pre>
90
+ <pre data-group="i2i" data-lang="js" hidden><code>import { InferenceClient } from "@huggingface/inference";
91
+ import { readFile, writeFile } from "node:fs/promises";
92
+
93
+ const client = new InferenceClient(process.env.HF_TOKEN);
94
+
95
+ const image = await client.imageToImage({
96
+ provider: "replicate",
97
+ model: "black-forest-labs/FLUX.1-Kontext-dev",
98
+ inputs: new Blob([await readFile("cat.png")]),
99
+ parameters: { prompt: "Turn the cat into a tiger" },
100
+ });
101
+ await writeFile("tiger.png", Buffer.from(await image.arrayBuffer()));</code></pre>
102
+ </section>
103
+
104
+ <section>
105
+ <h2>Text to video</h2>
106
+ <p class="model">Model: <a href="https://huggingface.co/Wan-AI/Wan2.2-T2V-A14B-Diffusers" target="_blank" rel="noopener">Wan-AI/Wan2.2-T2V-A14B-Diffusers</a></p>
107
+ <div class="tabs" data-group="t2v">
108
+ <button class="tab active" data-lang="python">Python</button>
109
+ <button class="tab" data-lang="js">JavaScript</button>
110
+ </div>
111
+ <pre data-group="t2v" data-lang="python"><code>import os
112
+ from huggingface_hub import InferenceClient
113
+
114
+ client = InferenceClient(provider="replicate", api_key=os.environ["HF_TOKEN"])
115
+
116
+ video = client.text_to_video(
117
+ "A young man walking on the street at sunset",
118
+ model="Wan-AI/Wan2.2-T2V-A14B-Diffusers",
119
+ )
120
+ with open("video.mp4", "wb") as f:
121
+ f.write(video)</code></pre>
122
+ <pre data-group="t2v" data-lang="js" hidden><code>import { InferenceClient } from "@huggingface/inference";
123
+ import { writeFile } from "node:fs/promises";
124
+
125
+ const client = new InferenceClient(process.env.HF_TOKEN);
126
+
127
+ const video = await client.textToVideo({
128
+ provider: "replicate",
129
+ model: "Wan-AI/Wan2.2-T2V-A14B-Diffusers",
130
+ inputs: "A young man walking on the street at sunset",
131
+ });
132
+ await writeFile("video.mp4", Buffer.from(await video.arrayBuffer()));</code></pre>
133
+ </section>
134
+
135
+ <section>
136
+ <h2>Speech recognition</h2>
137
+ <p class="model">Model: <a href="https://huggingface.co/openai/whisper-large-v3" target="_blank" rel="noopener">openai/whisper-large-v3</a></p>
138
+ <div class="tabs" data-group="asr">
139
+ <button class="tab active" data-lang="python">Python</button>
140
+ <button class="tab" data-lang="js">JavaScript</button>
141
+ </div>
142
+ <pre data-group="asr" data-lang="python"><code>import os
143
+ from huggingface_hub import InferenceClient
144
+
145
+ client = InferenceClient(provider="replicate", api_key=os.environ["HF_TOKEN"])
146
+
147
+ result = client.automatic_speech_recognition(
148
+ "sample.flac",
149
+ model="openai/whisper-large-v3",
150
+ )
151
+ print(result.text)</code></pre>
152
+ <pre data-group="asr" data-lang="js" hidden><code>import { InferenceClient } from "@huggingface/inference";
153
+ import { readFile } from "node:fs/promises";
154
+
155
+ const client = new InferenceClient(process.env.HF_TOKEN);
156
+
157
+ const result = await client.automaticSpeechRecognition({
158
+ provider: "replicate",
159
+ model: "openai/whisper-large-v3",
160
+ data: new Blob([await readFile("sample.flac")]),
161
+ });
162
+ console.log(result.text);</code></pre>
163
+ </section>
164
+
165
+ <section>
166
+ <h2>Text to speech</h2>
167
+ <p class="model">Model: <a href="https://huggingface.co/ResembleAI/chatterbox" target="_blank" rel="noopener">ResembleAI/chatterbox</a></p>
168
+ <div class="tabs" data-group="tts">
169
+ <button class="tab active" data-lang="python">Python</button>
170
+ <button class="tab" data-lang="js">JavaScript</button>
171
+ </div>
172
+ <pre data-group="tts" data-lang="python"><code>import os
173
+ from huggingface_hub import InferenceClient
174
+
175
+ client = InferenceClient(provider="replicate", api_key=os.environ["HF_TOKEN"])
176
+
177
+ audio = client.text_to_speech(
178
+ "Hello from Replicate on Hugging Face!",
179
+ model="ResembleAI/chatterbox",
180
+ )
181
+ with open("speech.wav", "wb") as f:
182
+ f.write(audio)</code></pre>
183
+ <pre data-group="tts" data-lang="js" hidden><code>import { InferenceClient } from "@huggingface/inference";
184
+ import { writeFile } from "node:fs/promises";
185
+
186
+ const client = new InferenceClient(process.env.HF_TOKEN);
187
+
188
+ const audio = await client.textToSpeech({
189
+ provider: "replicate",
190
+ model: "ResembleAI/chatterbox",
191
+ inputs: "Hello from Replicate on Hugging Face!",
192
+ });
193
+ await writeFile("speech.wav", Buffer.from(await audio.arrayBuffer()));</code></pre>
194
+ </section>
195
+
196
+ <footer>
197
+ <p>
198
+ Need cURL or more tasks? See the
199
+ <a href="https://huggingface.co/docs/inference-providers/providers/replicate" target="_blank" rel="noopener">Replicate provider docs</a>.
200
+ Want the full Replicate API? Visit <a href="https://replicate.com/docs" target="_blank" rel="noopener">replicate.com/docs</a>.
201
+ </p>
202
+ </footer>
203
+ </main>
204
+
205
+ <script>
206
+ document.querySelectorAll(".tab").forEach(function (btn) {
207
+ btn.addEventListener("click", function () {
208
+ var lang = btn.dataset.lang;
209
+ document.querySelectorAll(".tab").forEach(function (t) {
210
+ t.classList.toggle("active", t.dataset.lang === lang);
211
+ });
212
+ document.querySelectorAll("pre[data-lang]").forEach(function (p) {
213
+ p.hidden = p.dataset.lang !== lang;
214
+ });
215
+ });
216
+ });
217
+ </script>
218
  </body>
219
  </html>
style.css CHANGED
@@ -1,28 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  body {
2
- padding: 2rem;
3
- font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
 
 
 
 
 
 
 
 
 
4
  }
5
 
6
  h1 {
7
- font-size: 16px;
8
- margin-top: 0;
 
9
  }
10
 
11
- p {
12
- color: rgb(107, 114, 128);
13
- font-size: 15px;
14
- margin-bottom: 10px;
15
- margin-top: 5px;
16
  }
17
 
18
- .card {
19
- max-width: 620px;
20
- margin: 0 auto;
21
- padding: 16px;
22
- border: 1px solid lightgray;
23
- border-radius: 16px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  }
25
 
26
- .card p:last-child {
27
- margin-bottom: 0;
 
 
 
 
28
  }
 
1
+ :root {
2
+ --bg: #ffffff;
3
+ --fg: #111827;
4
+ --muted: #6b7280;
5
+ --border: #e5e7eb;
6
+ --code-bg: #0f172a;
7
+ --code-fg: #e2e8f0;
8
+ --accent: #ea2804;
9
+ }
10
+
11
+ @media (prefers-color-scheme: dark) {
12
+ :root {
13
+ --bg: #0b0f19;
14
+ --fg: #f3f4f6;
15
+ --muted: #9ca3af;
16
+ --border: #1f2937;
17
+ --code-bg: #111827;
18
+ }
19
+ }
20
+
21
+ * {
22
+ box-sizing: border-box;
23
+ }
24
+
25
  body {
26
+ margin: 0;
27
+ background: var(--bg);
28
+ color: var(--fg);
29
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
30
+ line-height: 1.6;
31
+ }
32
+
33
+ main {
34
+ max-width: 860px;
35
+ margin: 0 auto;
36
+ padding: 2.5rem 1.25rem 4rem;
37
  }
38
 
39
  h1 {
40
+ font-size: 2rem;
41
+ line-height: 1.2;
42
+ margin: 0 0 0.75rem;
43
  }
44
 
45
+ h2 {
46
+ font-size: 1.25rem;
47
+ margin: 0 0 0.5rem;
 
 
48
  }
49
 
50
+ section {
51
+ border-top: 1px solid var(--border);
52
+ padding-top: 1.5rem;
53
+ margin-top: 1.5rem;
54
+ }
55
+
56
+ a {
57
+ color: var(--accent);
58
+ }
59
+
60
+ .lede {
61
+ font-size: 1.1rem;
62
+ color: var(--muted);
63
+ margin: 0 0 1rem;
64
+ }
65
+
66
+ .links {
67
+ display: flex;
68
+ flex-wrap: wrap;
69
+ gap: 0.5rem;
70
+ }
71
+
72
+ .links a {
73
+ border: 1px solid var(--border);
74
+ border-radius: 999px;
75
+ padding: 0.3rem 0.85rem;
76
+ text-decoration: none;
77
+ font-size: 0.9rem;
78
+ }
79
+
80
+ .links a:hover {
81
+ border-color: var(--accent);
82
+ }
83
+
84
+ .model,
85
+ .note {
86
+ color: var(--muted);
87
+ font-size: 0.9rem;
88
+ margin: 0 0 0.75rem;
89
+ }
90
+
91
+ .tabs {
92
+ display: flex;
93
+ gap: 0.25rem;
94
+ }
95
+
96
+ .tab {
97
+ border: 1px solid var(--border);
98
+ border-bottom: none;
99
+ border-radius: 6px 6px 0 0;
100
+ background: transparent;
101
+ color: var(--muted);
102
+ padding: 0.35rem 0.9rem;
103
+ font-size: 0.85rem;
104
+ cursor: pointer;
105
+ }
106
+
107
+ .tab.active {
108
+ background: var(--code-bg);
109
+ color: var(--code-fg);
110
+ border-color: var(--code-bg);
111
+ }
112
+
113
+ pre {
114
+ margin: 0;
115
+ background: var(--code-bg);
116
+ color: var(--code-fg);
117
+ padding: 1rem;
118
+ border-radius: 0 6px 6px 6px;
119
+ overflow-x: auto;
120
+ font-size: 0.85rem;
121
+ }
122
+
123
+ code {
124
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
125
+ }
126
+
127
+ p code {
128
+ background: var(--border);
129
+ padding: 0.1rem 0.3rem;
130
+ border-radius: 4px;
131
+ font-size: 0.85em;
132
  }
133
 
134
+ footer {
135
+ border-top: 1px solid var(--border);
136
+ margin-top: 2rem;
137
+ padding-top: 1.5rem;
138
+ color: var(--muted);
139
+ font-size: 0.9rem;
140
  }