Spaces:
Build error
Build error
Upload 4 files
Browse files- Dockerfile +12 -0
- app.py +26 -0
- huggingface.yml +1 -0
- requirements.txt +5 -0
Dockerfile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
EXPOSE 7860
|
| 11 |
+
|
| 12 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModel
|
| 3 |
+
import torch
|
| 4 |
+
from sentence_transformers import SentenceTransformer
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# Load your model with trust_remote_code=True
|
| 8 |
+
model = SentenceTransformer("truong1301/bi-encode-HG-DOCS", trust_remote_code=True)
|
| 9 |
+
|
| 10 |
+
# Define a function to get embeddings
|
| 11 |
+
def get_embedding(text):
|
| 12 |
+
with torch.no_grad():
|
| 13 |
+
embeddings = model.encode(text)
|
| 14 |
+
return embeddings
|
| 15 |
+
|
| 16 |
+
# Create a Gradio interface
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=get_embedding,
|
| 19 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
| 20 |
+
outputs="json",
|
| 21 |
+
title="Embedding Generator",
|
| 22 |
+
description="Get embeddings using ICTuniverse/tuned-bi-encoder"
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Launch the Gradio app
|
| 26 |
+
iface.launch()
|
huggingface.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
sdk: docker
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
torch
|
| 3 |
+
sentence-transformers
|
| 4 |
+
uvicorn
|
| 5 |
+
gradio
|