lamhieu commited on
Commit
1e86e8b
Β·
1 Parent(s): 4af7aed

chore: update playground examples

Browse files
Files changed (2) hide show
  1. README.md +6 -4
  2. lightweight_embeddings/__init__.py +74 -46
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Lightweight Embeddings
3
- emoji: 🌍
4
- colorFrom: green
5
- colorTo: green
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
- ## πŸš€ **Lightweight Embeddings API**
115
-
116
- Welcome to the **Lightweight Embeddings API**, a fast, free, and unlimited service for generating multilingual embeddings and reranking, supporting both **text** and **image** inputs. Discover its key features and capabilities below:
117
- """
118
- )
119
- gr.Markdown(
120
- f"""
121
- ---
122
- ### πŸ“¦ Project Details
123
- - **Description**: {root_data["description"]}
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
- # Embeddings Playground
134
- with gr.Accordion("πŸ”¬ Try the Embeddings Playground", open=True):
135
- gr.Markdown(
136
- "Enter your **text** or an **image URL**, pick a model, "
137
- "then click **Generate** to get embeddings from the `/v1/embeddings` API."
138
- )
139
- input_text = gr.Textbox(
140
- label="Input Text or Image URL",
141
- placeholder="Type some text or paste an image URL...",
142
- lines=3,
143
- )
144
- model_dropdown = gr.Dropdown(
145
- choices=model_options,
146
- value=model_options[0],
147
- label="Select Model",
148
- )
149
- generate_btn = gr.Button("Generate Embeddings")
150
- output_json = gr.Textbox(
151
- label="Embeddings API Response",
152
- lines=15,
153
- interactive=False,
154
- )
155
-
156
- # Link the button to the inference function
157
- generate_btn.click(
158
- fn=call_embeddings_api,
159
- inputs=[input_text, model_dropdown],
160
- outputs=output_json,
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