Spaces:
Running
Running
Patryk Ptasiński
commited on
Commit
·
06197a9
1
Parent(s):
3a1e953
Update API documentation to clarify Hugging Face Spaces queue requirements
Browse files
CLAUDE.md
CHANGED
|
@@ -36,22 +36,21 @@ The application consists of a single `app.py` file with:
|
|
| 36 |
|
| 37 |
## Important Configuration Details
|
| 38 |
|
| 39 |
-
- **
|
| 40 |
- **CPU Mode**: Explicitly set to CPU to avoid GPU requirements
|
| 41 |
- **Trust Remote Code**: Model uses `trust_remote_code=True` for custom Nomic model code
|
| 42 |
-
- **API
|
| 43 |
|
| 44 |
## API Usage
|
| 45 |
|
| 46 |
-
|
| 47 |
-
```
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
}
|
| 52 |
```
|
| 53 |
|
| 54 |
-
|
| 55 |
|
| 56 |
## Deployment Notes
|
| 57 |
|
|
|
|
| 36 |
|
| 37 |
## Important Configuration Details
|
| 38 |
|
| 39 |
+
- **Queue**: Hugging Face Spaces enforces queuing at infrastructure level, even without `.queue()` in code
|
| 40 |
- **CPU Mode**: Explicitly set to CPU to avoid GPU requirements
|
| 41 |
- **Trust Remote Code**: Model uses `trust_remote_code=True` for custom Nomic model code
|
| 42 |
+
- **API Access**: Direct HTTP requires queue protocol; use Gradio client libraries instead
|
| 43 |
|
| 44 |
## API Usage
|
| 45 |
|
| 46 |
+
Use Gradio client libraries for API access:
|
| 47 |
+
```python
|
| 48 |
+
from gradio_client import Client
|
| 49 |
+
client = Client("ipepe/nomic-embeddings")
|
| 50 |
+
result = client.predict("text to embed", api_name="/predict")
|
|
|
|
| 51 |
```
|
| 52 |
|
| 53 |
+
Direct HTTP requires implementing Gradio's queue protocol (join queue, SSE listening, session management).
|
| 54 |
|
| 55 |
## Deployment Notes
|
| 56 |
|
app.py
CHANGED
|
@@ -30,30 +30,18 @@ with gr.Blocks(title="Nomic Text Embeddings") as app:
|
|
| 30 |
# Add API usage guide
|
| 31 |
gr.Markdown("## API Usage")
|
| 32 |
gr.Markdown("""
|
| 33 |
-
You can use this API programmatically
|
| 34 |
|
| 35 |
-
###
|
| 36 |
```bash
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
-d '{
|
| 40 |
-
"fn_index": 0,
|
| 41 |
-
"data": ["Your text to embed goes here"]
|
| 42 |
-
}'
|
| 43 |
-
```
|
| 44 |
-
|
| 45 |
-
### Python Example (using requests)
|
| 46 |
-
```python
|
| 47 |
-
import requests
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
json={"fn_index": 0, "data": ["Your text to embed goes here"]}
|
| 52 |
-
)
|
| 53 |
-
print(response.json()) # Returns the embedding array
|
| 54 |
```
|
| 55 |
|
| 56 |
-
### Python Example (
|
| 57 |
```python
|
| 58 |
from gradio_client import Client
|
| 59 |
|
|
@@ -74,6 +62,14 @@ with gr.Blocks(title="Nomic Text Embeddings") as app:
|
|
| 74 |
console.log(result.data);
|
| 75 |
```
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
The response will contain the embedding array as a list of floats.
|
| 78 |
""")
|
| 79 |
|
|
|
|
| 30 |
# Add API usage guide
|
| 31 |
gr.Markdown("## API Usage")
|
| 32 |
gr.Markdown("""
|
| 33 |
+
You can use this API programmatically. Hugging Face Spaces requires using their client libraries which handle queuing automatically.
|
| 34 |
|
| 35 |
+
### Quick Command-Line Usage
|
| 36 |
```bash
|
| 37 |
+
# Install gradio client
|
| 38 |
+
pip install gradio_client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
# Generate embedding with one command
|
| 41 |
+
python -c "from gradio_client import Client; print(Client('ipepe/nomic-embeddings').predict('Your text here', api_name='/predict'))"
|
|
|
|
|
|
|
|
|
|
| 42 |
```
|
| 43 |
|
| 44 |
+
### Python Example (Recommended)
|
| 45 |
```python
|
| 46 |
from gradio_client import Client
|
| 47 |
|
|
|
|
| 62 |
console.log(result.data);
|
| 63 |
```
|
| 64 |
|
| 65 |
+
### Direct HTTP (Advanced)
|
| 66 |
+
Direct HTTP requests require implementing the Gradio queue protocol:
|
| 67 |
+
1. POST to `/queue/join` to join queue
|
| 68 |
+
2. Listen to `/queue/data` via SSE for results
|
| 69 |
+
3. Handle session management
|
| 70 |
+
|
| 71 |
+
For direct HTTP, we recommend using the official Gradio clients above which handle this automatically.
|
| 72 |
+
|
| 73 |
The response will contain the embedding array as a list of floats.
|
| 74 |
""")
|
| 75 |
|