Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,3 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from gradio_client import Client
|
| 3 |
-
|
| 4 |
|
| 5 |
title = """# 🙋🏻♂️Welcome to tonic's e5 connector for e5Mistral7b
|
| 6 |
⚒️this connector looks like openai embeddings but uses e5Mistral7b - so you can use it as a drop in replacement for the open ai api ⚒️
|
|
@@ -19,10 +16,27 @@ def get_embeddings(task, input_text):
|
|
| 19 |
except Exception as e:
|
| 20 |
return str(e)
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
def generate_embeddings(input_text, model, encoding_format, user):
|
| 24 |
embeddings = get_embeddings(model, input_text)
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
with gr.Blocks() as app:
|
| 28 |
gr.Markdown(title)
|
|
@@ -33,7 +47,7 @@ with gr.Blocks() as app:
|
|
| 33 |
user = gr.Textbox(label="User", placeholder="Enter user identifier (optional)")
|
| 34 |
submit_button = gr.Button("Generate Embeddings")
|
| 35 |
|
| 36 |
-
output = gr.
|
| 37 |
|
| 38 |
submit_button.click(
|
| 39 |
fn=generate_embeddings,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
title = """# 🙋🏻♂️Welcome to tonic's e5 connector for e5Mistral7b
|
| 3 |
⚒️this connector looks like openai embeddings but uses e5Mistral7b - so you can use it as a drop in replacement for the open ai api ⚒️
|
|
|
|
| 16 |
except Exception as e:
|
| 17 |
return str(e)
|
| 18 |
|
| 19 |
+
def format_response(embeddings, model):
|
| 20 |
+
return {
|
| 21 |
+
"data": [
|
| 22 |
+
{
|
| 23 |
+
"embedding": embeddings,
|
| 24 |
+
"index": 0,
|
| 25 |
+
"object": "embedding"
|
| 26 |
+
}
|
| 27 |
+
],
|
| 28 |
+
"model": model,
|
| 29 |
+
"object": "list",
|
| 30 |
+
"usage": {
|
| 31 |
+
"prompt_tokens": 17
|
| 32 |
+
"total_tokens": 17
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
def generate_embeddings(input_text, model, encoding_format, user):
|
| 37 |
embeddings = get_embeddings(model, input_text)
|
| 38 |
+
formatted_response = format_response(embeddings, model)
|
| 39 |
+
return formatted_response
|
| 40 |
|
| 41 |
with gr.Blocks() as app:
|
| 42 |
gr.Markdown(title)
|
|
|
|
| 47 |
user = gr.Textbox(label="User", placeholder="Enter user identifier (optional)")
|
| 48 |
submit_button = gr.Button("Generate Embeddings")
|
| 49 |
|
| 50 |
+
output = gr.JSON(label="Embeddings Output")
|
| 51 |
|
| 52 |
submit_button.click(
|
| 53 |
fn=generate_embeddings,
|