Spaces:
Running
Running
chore: update playground examples
Browse files- README.md +6 -4
- lightweight_embeddings/__init__.py +74 -46
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title: Lightweight Embeddings
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
app_file: app.py
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
# π LightweightEmbeddings: Multilingual, Fast, and Unlimited
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Lightweight Embeddings API
|
| 3 |
+
emoji: π» / π§¬
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: docker
|
| 7 |
app_file: app.py
|
| 8 |
+
pinned: false
|
| 9 |
+
header: mini
|
| 10 |
---
|
| 11 |
|
| 12 |
# π LightweightEmbeddings: Multilingual, Fast, and Unlimited
|
lightweight_embeddings/__init__.py
CHANGED
|
@@ -111,54 +111,82 @@ def create_main_interface():
|
|
| 111 |
# Project Info
|
| 112 |
gr.Markdown(
|
| 113 |
"""
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
### π Links
|
| 126 |
-
- [Documentation]({root_data["docs"]}) | [GitHub]({root_data["github"]}) | [Playground]({root_data["spaces"]})
|
| 127 |
-
|
| 128 |
-
### π‘ How to Use
|
| 129 |
-
Visit **/docs** for API documentation or try the playground below! π
|
| 130 |
-
"""
|
| 131 |
)
|
| 132 |
|
| 133 |
-
#
|
| 134 |
-
with gr.
|
| 135 |
-
gr.
|
| 136 |
-
"
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
return demo
|
| 164 |
|
|
|
|
| 111 |
# Project Info
|
| 112 |
gr.Markdown(
|
| 113 |
"""
|
| 114 |
+
## π **Lightweight Embeddings API**
|
| 115 |
+
The **Lightweight Embeddings API** is a fast, free, and multilingual service designed for generating embeddings and reranking with support for both **text** and **image** inputs. Get started below by exploring our interactive playground or using the cURL examples provided.
|
| 116 |
+
---
|
| 117 |
+
### π¦ Features
|
| 118 |
+
- **Multilingual Support**: Process inputs in multiple languages.
|
| 119 |
+
- **Versatile API**: Generate embeddings, perform ranking, and more.
|
| 120 |
+
- **Developer-Friendly**: Quick to integrate with documentation and examples.
|
| 121 |
+
|
| 122 |
+
### π Links
|
| 123 |
+
- [Documentation]({root_data["docs"]}) | [GitHub]({root_data["github"]}) | [Playground]({root_data["spaces"]})
|
| 124 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
)
|
| 126 |
|
| 127 |
+
# Split Layout: Playground and cURL Examples
|
| 128 |
+
with gr.Row():
|
| 129 |
+
with gr.Column():
|
| 130 |
+
gr.Markdown("### π¬ Try the Embeddings Playground")
|
| 131 |
+
input_text = gr.Textbox(
|
| 132 |
+
label="Input Text or Image URL",
|
| 133 |
+
placeholder="Enter text or an image URL...",
|
| 134 |
+
lines=3,
|
| 135 |
+
)
|
| 136 |
+
model_dropdown = gr.Dropdown(
|
| 137 |
+
choices=model_options,
|
| 138 |
+
value=model_options[0],
|
| 139 |
+
label="Select Model",
|
| 140 |
+
)
|
| 141 |
+
generate_btn = gr.Button("Generate Embeddings")
|
| 142 |
+
output_json = gr.Textbox(
|
| 143 |
+
label="Embeddings API Response",
|
| 144 |
+
lines=10,
|
| 145 |
+
interactive=False,
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
# Link button to inference function
|
| 149 |
+
generate_btn.click(
|
| 150 |
+
fn=call_embeddings_api,
|
| 151 |
+
inputs=[input_text, model_dropdown],
|
| 152 |
+
outputs=output_json,
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
with gr.Column():
|
| 156 |
+
gr.Markdown(
|
| 157 |
+
"""
|
| 158 |
+
### π οΈ cURL Examples
|
| 159 |
+
|
| 160 |
+
**Generate Embeddings**
|
| 161 |
+
```bash
|
| 162 |
+
curl -X 'POST' \\
|
| 163 |
+
'https://lamhieu-lightweight-embeddings.hf.space/v1/embeddings' \\
|
| 164 |
+
-H 'accept: application/json' \\
|
| 165 |
+
-H 'Content-Type: application/json' \\
|
| 166 |
+
-d '{
|
| 167 |
+
"model": "multilingual-e5-small",
|
| 168 |
+
"input": "Translate this text into Spanish."
|
| 169 |
+
}'
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
**Perform Ranking**
|
| 173 |
+
```bash
|
| 174 |
+
curl -X 'POST' \\
|
| 175 |
+
'https://lamhieu-lightweight-embeddings.hf.space/v1/rank' \\
|
| 176 |
+
-H 'accept: application/json' \\
|
| 177 |
+
-H 'Content-Type: application/json' \\
|
| 178 |
+
-d '{
|
| 179 |
+
"model": "multilingual-e5-small",
|
| 180 |
+
"queries": "Find the best match for this query.",
|
| 181 |
+
"candidates": [
|
| 182 |
+
"Candidate A",
|
| 183 |
+
"Candidate B",
|
| 184 |
+
"Candidate C"
|
| 185 |
+
]
|
| 186 |
+
}'
|
| 187 |
+
```
|
| 188 |
+
"""
|
| 189 |
+
)
|
| 190 |
|
| 191 |
return demo
|
| 192 |
|