Spaces:
Running
Running
chore: update something
Browse files
lightweight_embeddings/__init__.py
CHANGED
|
@@ -84,7 +84,7 @@ from .router import router
|
|
| 84 |
app.include_router(router, prefix="/v1")
|
| 85 |
|
| 86 |
|
| 87 |
-
def call_embeddings_api(user_input: str, selected_model: str) -> str:
|
| 88 |
"""
|
| 89 |
Send a request to the /v1/embeddings endpoint with the given model and input.
|
| 90 |
Return a pretty-printed JSON response or an error message.
|
|
@@ -94,6 +94,10 @@ def call_embeddings_api(user_input: str, selected_model: str) -> str:
|
|
| 94 |
"input": user_input,
|
| 95 |
}
|
| 96 |
headers = {"Content-Type": "application/json"}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
try:
|
| 99 |
response = requests.post(
|
|
@@ -197,6 +201,12 @@ def create_main_interface():
|
|
| 197 |
value=model_options[0],
|
| 198 |
label="Select Model",
|
| 199 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
generate_btn = gr.Button("Generate Embeddings")
|
| 201 |
output_json = gr.Textbox(
|
| 202 |
label="Embeddings API Response",
|
|
@@ -206,7 +216,7 @@ def create_main_interface():
|
|
| 206 |
|
| 207 |
generate_btn.click(
|
| 208 |
fn=call_embeddings_api,
|
| 209 |
-
inputs=[input_text, model_dropdown],
|
| 210 |
outputs=output_json,
|
| 211 |
)
|
| 212 |
|
|
@@ -217,6 +227,19 @@ def create_main_interface():
|
|
| 217 |
|
| 218 |
**Generate Embeddings (OpenAI compatible)**
|
| 219 |
```bash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
curl -X 'POST' \\
|
| 221 |
'https://lamhieu-lightweight-embeddings.hf.space/v1/embeddings' \\
|
| 222 |
-H 'accept: application/json' \\
|
|
@@ -233,6 +256,7 @@ def create_main_interface():
|
|
| 233 |
'https://lamhieu-lightweight-embeddings.hf.space/v1/rank' \\
|
| 234 |
-H 'accept: application/json' \\
|
| 235 |
-H 'Content-Type: application/json' \\
|
|
|
|
| 236 |
-d '{
|
| 237 |
"model": "snowflake-arctic-embed-l-v2.0",
|
| 238 |
"queries": "That is a happy person",
|
|
@@ -243,6 +267,8 @@ def create_main_interface():
|
|
| 243 |
]
|
| 244 |
}'
|
| 245 |
```
|
|
|
|
|
|
|
| 246 |
"""
|
| 247 |
)
|
| 248 |
|
|
|
|
| 84 |
app.include_router(router, prefix="/v1")
|
| 85 |
|
| 86 |
|
| 87 |
+
def call_embeddings_api(user_input: str, selected_model: str, auth_key: str = "") -> str:
|
| 88 |
"""
|
| 89 |
Send a request to the /v1/embeddings endpoint with the given model and input.
|
| 90 |
Return a pretty-printed JSON response or an error message.
|
|
|
|
| 94 |
"input": user_input,
|
| 95 |
}
|
| 96 |
headers = {"Content-Type": "application/json"}
|
| 97 |
+
|
| 98 |
+
# Add authorization header if auth_key is provided
|
| 99 |
+
if auth_key.strip():
|
| 100 |
+
headers["Authorization"] = f"Bearer {auth_key.strip()}"
|
| 101 |
|
| 102 |
try:
|
| 103 |
response = requests.post(
|
|
|
|
| 201 |
value=model_options[0],
|
| 202 |
label="Select Model",
|
| 203 |
)
|
| 204 |
+
auth_key = gr.Textbox(
|
| 205 |
+
label="Authorization Key (Optional)",
|
| 206 |
+
placeholder="Enter your auth key if required...",
|
| 207 |
+
type="password",
|
| 208 |
+
lines=1,
|
| 209 |
+
)
|
| 210 |
generate_btn = gr.Button("Generate Embeddings")
|
| 211 |
output_json = gr.Textbox(
|
| 212 |
label="Embeddings API Response",
|
|
|
|
| 216 |
|
| 217 |
generate_btn.click(
|
| 218 |
fn=call_embeddings_api,
|
| 219 |
+
inputs=[input_text, model_dropdown, auth_key],
|
| 220 |
outputs=output_json,
|
| 221 |
)
|
| 222 |
|
|
|
|
| 227 |
|
| 228 |
**Generate Embeddings (OpenAI compatible)**
|
| 229 |
```bash
|
| 230 |
+
curl -X 'POST' \\
|
| 231 |
+
'https://lamhieu-lightweight-embeddings.hf.space/v1/embeddings' \\
|
| 232 |
+
-H 'accept: application/json' \\
|
| 233 |
+
-H 'Content-Type: application/json' \\
|
| 234 |
+
-H 'Authorization: Bearer YOUR_AUTH_KEY' \\
|
| 235 |
+
-d '{
|
| 236 |
+
"model": "snowflake-arctic-embed-l-v2.0",
|
| 237 |
+
"input": "That is a happy person"
|
| 238 |
+
}'
|
| 239 |
+
```
|
| 240 |
+
|
| 241 |
+
**Generate Embeddings (without auth)**
|
| 242 |
+
```bash
|
| 243 |
curl -X 'POST' \\
|
| 244 |
'https://lamhieu-lightweight-embeddings.hf.space/v1/embeddings' \\
|
| 245 |
-H 'accept: application/json' \\
|
|
|
|
| 256 |
'https://lamhieu-lightweight-embeddings.hf.space/v1/rank' \\
|
| 257 |
-H 'accept: application/json' \\
|
| 258 |
-H 'Content-Type: application/json' \\
|
| 259 |
+
-H 'Authorization: Bearer YOUR_AUTH_KEY' \\
|
| 260 |
-d '{
|
| 261 |
"model": "snowflake-arctic-embed-l-v2.0",
|
| 262 |
"queries": "That is a happy person",
|
|
|
|
| 267 |
]
|
| 268 |
}'
|
| 269 |
```
|
| 270 |
+
|
| 271 |
+
💡 **Note**: Add Authorization header only if ACCESS_TOKEN environment variable is set on the server.
|
| 272 |
"""
|
| 273 |
)
|
| 274 |
|