Patryk Ptasiński commited on
Commit
65ff348
·
1 Parent(s): 9530053

Disable queue to allow direct API calls

Browse files
Files changed (1) hide show
  1. app.py +24 -18
app.py CHANGED
@@ -30,9 +30,30 @@ 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. Hugging Face Spaces use a queue system for API calls.
34
 
35
- ### Recommended: Python Client
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  ```python
37
  from gradio_client import Client
38
 
@@ -44,21 +65,6 @@ with gr.Blocks(title="Nomic Text Embeddings") as app:
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";
@@ -72,4 +78,4 @@ with gr.Blocks(title="Nomic Text Embeddings") as app:
72
  """)
73
 
74
  if __name__ == '__main__':
75
- app.queue().launch(server_name="0.0.0.0", show_error=True, server_port=7860)
 
30
  # Add API usage guide
31
  gr.Markdown("## API Usage")
32
  gr.Markdown("""
33
+ You can use this API programmatically with direct HTTP requests (queue disabled).
34
 
35
+ ### Using cURL
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
+ ### Python Example (using requests)
46
+ ```python
47
+ import requests
48
+
49
+ response = requests.post(
50
+ "https://ipepe-nomic-embeddings.hf.space/api/predict",
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 (using Gradio Client)
57
  ```python
58
  from gradio_client import Client
59
 
 
65
  print(result) # Returns the embedding array
66
  ```
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  ### JavaScript/Node.js Example
69
  ```javascript
70
  import { client } from "@gradio/client";
 
78
  """)
79
 
80
  if __name__ == '__main__':
81
+ app.launch(server_name="0.0.0.0", show_error=True, server_port=7860)