Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -141,6 +141,27 @@ def search_similar_sentences(input_question, corpus_sentences, corpus_embeddings
|
|
141 |
results = [(corpus_sentences[i], top_k_scores[i]) for i in top_k_indices]
|
142 |
return results
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
def app_interface():
|
146 |
corpus_sentences = []
|
@@ -211,6 +232,22 @@ def app_interface():
|
|
211 |
outputs=search_results_output
|
212 |
)
|
213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
with gr.Row():
|
215 |
with gr.Column():
|
216 |
input_text_box
|
|
|
141 |
results = [(corpus_sentences[i], top_k_scores[i]) for i in top_k_indices]
|
142 |
return results
|
143 |
|
144 |
+
# openai response object formatting
|
145 |
+
def format_response(embeddings):
|
146 |
+
return {
|
147 |
+
"data": [
|
148 |
+
{
|
149 |
+
"embedding": embeddings,
|
150 |
+
"index": 0,
|
151 |
+
"object": "embedding"
|
152 |
+
}
|
153 |
+
],
|
154 |
+
"model": "e5-mistral",
|
155 |
+
"object": "list",
|
156 |
+
"usage": {
|
157 |
+
"prompt_tokens": 17,
|
158 |
+
"total_tokens": 17
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
def generate_and_format_embeddings(selected_task, input_text):
|
163 |
+
embeddings = compute_embeddings(selected_task, input_text)
|
164 |
+
return format_response(embeddings)
|
165 |
|
166 |
def app_interface():
|
167 |
corpus_sentences = []
|
|
|
232 |
outputs=search_results_output
|
233 |
)
|
234 |
|
235 |
+
with gr.Tab("Connector-like Embeddings"):
|
236 |
+
with gr.Row():
|
237 |
+
input_text_box_connector = gr.Textbox(label="Input Text", placeholder="Enter text or array of texts")
|
238 |
+
model_dropdown_connector = gr.Dropdown(label="Model", choices=["ArguAna", "ClimateFEVER", "DBPedia", "FEVER", "FiQA2018", "HotpotQA", "MSMARCO", "NFCorpus", "NQ", "QuoraRetrieval", "SCIDOCS", "SciFact", "Touche2020", "TRECCOVID"], value="text-embedding-ada-002")
|
239 |
+
encoding_format_connector = gr.Radio(label="Encoding Format", choices=["float", "base64"], value="float")
|
240 |
+
user_connector = gr.Textbox(label="User", placeholder="Enter user identifier (optional)")
|
241 |
+
submit_button_connector = gr.Button("Generate Embeddings")
|
242 |
+
|
243 |
+
output_display_connector = gr.JSON(label="Embeddings Output")
|
244 |
+
|
245 |
+
submit_button_connector.click(
|
246 |
+
fn=generate_and_format_embeddings,
|
247 |
+
inputs=[input_text_box_connector, model_dropdown_connector, encoding_format_connector, user_connector],
|
248 |
+
outputs=output_display_connector
|
249 |
+
)
|
250 |
+
|
251 |
with gr.Row():
|
252 |
with gr.Column():
|
253 |
input_text_box
|