Spaces:
Running
Running
support zero-gpu in system prompt for gradio
Browse files
app.py
CHANGED
@@ -185,6 +185,40 @@ def update_gradio_system_prompts():
|
|
185 |
# Base system prompt
|
186 |
base_prompt = """You are an expert Gradio developer. Write clean, idiomatic, and runnable Gradio applications for the user's request. Use the latest Gradio API and best practices. Output ONLY the code inside a ``` code block, and do not include any explanations or extra text. If the user provides a file or other context, use it as a reference. Make the app as self-contained as possible. Do NOT add the language name at the top of the code output.
|
187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
## Complete Gradio API Reference
|
189 |
|
190 |
This reference is automatically synced from https://www.gradio.app/llms.txt to ensure accuracy.
|
@@ -194,6 +228,40 @@ This reference is automatically synced from https://www.gradio.app/llms.txt to e
|
|
194 |
# Search-enabled prompt
|
195 |
search_prompt = """You are an expert Gradio developer with access to real-time web search. Write clean, idiomatic, and runnable Gradio applications for the user's request. Use the latest Gradio API and best practices. When needed, use web search to find current best practices or verify latest Gradio features. Output ONLY the code inside a ``` code block, and do not include any explanations or extra text. If the user provides a file or other context, use it as a reference. Make the app as self-contained as possible. Do NOT add the language name at the top of the code output.
|
196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
## Complete Gradio API Reference
|
198 |
|
199 |
This reference is automatically synced from https://www.gradio.app/llms.txt to ensure accuracy.
|
|
|
185 |
# Base system prompt
|
186 |
base_prompt = """You are an expert Gradio developer. Write clean, idiomatic, and runnable Gradio applications for the user's request. Use the latest Gradio API and best practices. Output ONLY the code inside a ``` code block, and do not include any explanations or extra text. If the user provides a file or other context, use it as a reference. Make the app as self-contained as possible. Do NOT add the language name at the top of the code output.
|
187 |
|
188 |
+
## ZeroGPU Integration (REQUIRED)
|
189 |
+
|
190 |
+
ALWAYS use ZeroGPU for GPU-dependent functions in Gradio apps:
|
191 |
+
|
192 |
+
1. Import the spaces module: `import spaces`
|
193 |
+
2. Decorate GPU-dependent functions with `@spaces.GPU`
|
194 |
+
3. For functions that may take longer than 60 seconds, specify duration: `@spaces.GPU(duration=120)`
|
195 |
+
|
196 |
+
Example usage:
|
197 |
+
```python
|
198 |
+
import spaces
|
199 |
+
from diffusers import DiffusionPipeline
|
200 |
+
|
201 |
+
pipe = DiffusionPipeline.from_pretrained(...)
|
202 |
+
pipe.to('cuda')
|
203 |
+
|
204 |
+
@spaces.GPU
|
205 |
+
def generate(prompt):
|
206 |
+
return pipe(prompt).images
|
207 |
+
|
208 |
+
gr.Interface(
|
209 |
+
fn=generate,
|
210 |
+
inputs=gr.Text(),
|
211 |
+
outputs=gr.Gallery(),
|
212 |
+
).launch()
|
213 |
+
```
|
214 |
+
|
215 |
+
Functions that typically need @spaces.GPU:
|
216 |
+
- Image generation (text-to-image, image-to-image)
|
217 |
+
- Video generation
|
218 |
+
- Audio/music generation
|
219 |
+
- Model inference with transformers, diffusers
|
220 |
+
- Any function using .to('cuda') or GPU operations
|
221 |
+
|
222 |
## Complete Gradio API Reference
|
223 |
|
224 |
This reference is automatically synced from https://www.gradio.app/llms.txt to ensure accuracy.
|
|
|
228 |
# Search-enabled prompt
|
229 |
search_prompt = """You are an expert Gradio developer with access to real-time web search. Write clean, idiomatic, and runnable Gradio applications for the user's request. Use the latest Gradio API and best practices. When needed, use web search to find current best practices or verify latest Gradio features. Output ONLY the code inside a ``` code block, and do not include any explanations or extra text. If the user provides a file or other context, use it as a reference. Make the app as self-contained as possible. Do NOT add the language name at the top of the code output.
|
230 |
|
231 |
+
## ZeroGPU Integration (REQUIRED)
|
232 |
+
|
233 |
+
ALWAYS use ZeroGPU for GPU-dependent functions in Gradio apps:
|
234 |
+
|
235 |
+
1. Import the spaces module: `import spaces`
|
236 |
+
2. Decorate GPU-dependent functions with `@spaces.GPU`
|
237 |
+
3. For functions that may take longer than 60 seconds, specify duration: `@spaces.GPU(duration=120)`
|
238 |
+
|
239 |
+
Example usage:
|
240 |
+
```python
|
241 |
+
import spaces
|
242 |
+
from diffusers import DiffusionPipeline
|
243 |
+
|
244 |
+
pipe = DiffusionPipeline.from_pretrained(...)
|
245 |
+
pipe.to('cuda')
|
246 |
+
|
247 |
+
@spaces.GPU
|
248 |
+
def generate(prompt):
|
249 |
+
return pipe(prompt).images
|
250 |
+
|
251 |
+
gr.Interface(
|
252 |
+
fn=generate,
|
253 |
+
inputs=gr.Text(),
|
254 |
+
outputs=gr.Gallery(),
|
255 |
+
).launch()
|
256 |
+
```
|
257 |
+
|
258 |
+
Functions that typically need @spaces.GPU:
|
259 |
+
- Image generation (text-to-image, image-to-image)
|
260 |
+
- Video generation
|
261 |
+
- Audio/music generation
|
262 |
+
- Model inference with transformers, diffusers
|
263 |
+
- Any function using .to('cuda') or GPU operations
|
264 |
+
|
265 |
## Complete Gradio API Reference
|
266 |
|
267 |
This reference is automatically synced from https://www.gradio.app/llms.txt to ensure accuracy.
|