Commit
·
6dff868
1
Parent(s):
0b0ed82
Add code embedding app with jina-embeddings-v2-base-code
Browse files- app.py +31 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from sentence_transformers import SentenceTransformer
|
3 |
+
|
4 |
+
# Load the Jina code-embedding model
|
5 |
+
model = SentenceTransformer(
|
6 |
+
"jinaai/jina-embeddings-v2-base-code",
|
7 |
+
trust_remote_code=True
|
8 |
+
)
|
9 |
+
|
10 |
+
def embed_code(code_snippet):
|
11 |
+
"""
|
12 |
+
Given a string containing code, return its embedding vector as a list.
|
13 |
+
"""
|
14 |
+
# The model.encode() method returns a numpy array; convert to list for display
|
15 |
+
embedding = model.encode(code_snippet)
|
16 |
+
return embedding.tolist()
|
17 |
+
|
18 |
+
# Build a simple Gradio interface
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=embed_code,
|
21 |
+
inputs=gr.Textbox(
|
22 |
+
lines=10,
|
23 |
+
placeholder="Paste your code snippet here..."
|
24 |
+
),
|
25 |
+
outputs="textbox",
|
26 |
+
title="Jina Code Embeddings",
|
27 |
+
description="Embeds a code snippet into a vector using jina-embeddings-v2-base-code."
|
28 |
+
)
|
29 |
+
|
30 |
+
if __name__ == "__main__":
|
31 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
sentence-transformers
|
3 |
+
torch
|