Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import src.Translate as Translate
|
|
4 |
from typing import Optional
|
5 |
from fastapi_mcp import FastApiMCP
|
6 |
from huggingface_hub import hf_hub_download, list_repo_files
|
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
# app = FastAPI(docs_url="/docs")
|
@@ -11,6 +12,7 @@ MODELS = {'enro': 'BlackKakapo/opus-mt-en-ro',
|
|
11 |
'roen': 'BlackKakapo/opus-mt-ro-en',
|
12 |
'gemma': 'Gargaz/gemma-2b-romanian-better',
|
13 |
'paraphrase': 'tuner007/pegasus_paraphrase'}
|
|
|
14 |
|
15 |
@app.get("/")
|
16 |
def index(request: Request):
|
@@ -110,6 +112,13 @@ def bergamot(input_text: list[str] = Query(description="Input list of strings"),
|
|
110 |
response, message_text = error, error
|
111 |
return {"input": input_text, "translated_text": response, "message_text": message_text}
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
# Create an MCP server based on this app
|
114 |
mcp = FastApiMCP(
|
115 |
app,
|
|
|
4 |
from typing import Optional
|
5 |
from fastapi_mcp import FastApiMCP
|
6 |
from huggingface_hub import hf_hub_download, list_repo_files
|
7 |
+
from sentence_transformers import SentenceTransformer
|
8 |
|
9 |
app = FastAPI()
|
10 |
# app = FastAPI(docs_url="/docs")
|
|
|
12 |
'roen': 'BlackKakapo/opus-mt-ro-en',
|
13 |
'gemma': 'Gargaz/gemma-2b-romanian-better',
|
14 |
'paraphrase': 'tuner007/pegasus_paraphrase'}
|
15 |
+
EMBEDDING_MODELS = ["all-MiniLM-L6-v2"]
|
16 |
|
17 |
@app.get("/")
|
18 |
def index(request: Request):
|
|
|
112 |
response, message_text = error, error
|
113 |
return {"input": input_text, "translated_text": response, "message_text": message_text}
|
114 |
|
115 |
+
@app.get("/paraphrase", operation_id="get_paraphrase", description="Paraphrase text", tags=["paraphrase"], summary="Paraphrase text")
|
116 |
+
def embed(text: str, model: str = EMBEDDING_MODELS[0]):
|
117 |
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
118 |
+
embeddings = model.encode(sentences)
|
119 |
+
print(embeddings.shape)
|
120 |
+
return {"input": text, "embeddings": embeddings, "shape": embeddings.shape}
|
121 |
+
|
122 |
# Create an MCP server based on this app
|
123 |
mcp = FastApiMCP(
|
124 |
app,
|