Patryk Ptasiński commited on
Commit
9530053
·
1 Parent(s): 329e33e

Update API documentation to clarify queue system requirements

Browse files
Files changed (1) hide show
  1. app.py +29 -32
app.py CHANGED
@@ -28,40 +28,11 @@ with gr.Blocks(title="Nomic Text Embeddings") as app:
28
  text_input.submit(embed, inputs=text_input, outputs=output)
29
 
30
  # Add API usage guide
31
- gr.Markdown("## API Usage with cURL")
32
  gr.Markdown("""
33
- You can use this API programmatically with cURL. Here are two methods:
34
 
35
- ### Method 1: Using the Gradio Client API
36
- ```bash
37
- curl -X POST https://ipepe-nomic-embeddings.hf.space/api/predict \
38
- -H "Content-Type: application/json" \
39
- -d '{
40
- "fn_index": 0,
41
- "data": ["Your text to embed goes here"]
42
- }'
43
- ```
44
-
45
- ### Method 2: Direct API endpoint
46
- ```bash
47
- curl -X POST https://ipepe-nomic-embeddings.hf.space/run/predict \
48
- -H "Content-Type: application/json" \
49
- -d '{
50
- "data": ["Your text to embed goes here"]
51
- }'
52
- ```
53
-
54
- The response will be in JSON format:
55
- ```json
56
- {
57
- "data": [[0.123, -0.456, 0.789, ...]],
58
- "duration": 0.123
59
- }
60
- ```
61
-
62
- Replace `https://ipepe-nomic-embeddings.hf.space` with your actual Space URL if different.
63
-
64
- ### Python Example
65
  ```python
66
  from gradio_client import Client
67
 
@@ -72,6 +43,32 @@ with gr.Blocks(title="Nomic Text Embeddings") as app:
72
  )
73
  print(result) # Returns the embedding array
74
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  """)
76
 
77
  if __name__ == '__main__':
 
28
  text_input.submit(embed, inputs=text_input, outputs=output)
29
 
30
  # Add API usage guide
31
+ gr.Markdown("## API Usage")
32
  gr.Markdown("""
33
+ You can use this API programmatically. Hugging Face Spaces use a queue system for API calls.
34
 
35
+ ### Recommended: Python Client
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  ```python
37
  from gradio_client import Client
38
 
 
43
  )
44
  print(result) # Returns the embedding array
45
  ```
46
+
47
+ ### Using cURL (requires session handling)
48
+ For direct HTTP requests, you need to:
49
+ 1. Join the queue
50
+ 2. Poll for results
51
+
52
+ This is more complex with cURL. Here's a simplified example using the Gradio Python client instead:
53
+
54
+ ```bash
55
+ # Install the client first
56
+ pip install gradio_client
57
+
58
+ # Then use Python
59
+ python -c "from gradio_client import Client; client = Client('ipepe/nomic-embeddings'); print(client.predict('Your text here', api_name='/predict'))"
60
+ ```
61
+
62
+ ### JavaScript/Node.js Example
63
+ ```javascript
64
+ import { client } from "@gradio/client";
65
+
66
+ const app = await client("ipepe/nomic-embeddings");
67
+ const result = await app.predict("/predict", ["Your text to embed goes here"]);
68
+ console.log(result.data);
69
+ ```
70
+
71
+ The response will contain the embedding array as a list of floats.
72
  """)
73
 
74
  if __name__ == '__main__':