Spaces:
Sleeping
Sleeping
Commit
·
ced8da9
1
Parent(s):
9cd1631
App version 1
Browse files- Chromadb/6c03f27c-dc64-4ecd-aff5-c13bd101e3f7/data_level0.bin +3 -0
- Chromadb/6c03f27c-dc64-4ecd-aff5-c13bd101e3f7/header.bin +3 -0
- Chromadb/6c03f27c-dc64-4ecd-aff5-c13bd101e3f7/length.bin +3 -0
- Chromadb/6c03f27c-dc64-4ecd-aff5-c13bd101e3f7/link_lists.bin +0 -0
- Chromadb/chroma.sqlite3 +0 -0
- Dockerfile +14 -0
- main.py +41 -0
- requirements.txt +4 -0
- utils.py +5 -0
Chromadb/6c03f27c-dc64-4ecd-aff5-c13bd101e3f7/data_level0.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a13e72541800c513c73dccea69f79e39cf4baef4fa23f7e117c0d6b0f5f99670
|
3 |
+
size 3212000
|
Chromadb/6c03f27c-dc64-4ecd-aff5-c13bd101e3f7/header.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0ec6df10978b056a10062ed99efeef2702fa4a1301fad702b53dd2517103c746
|
3 |
+
size 100
|
Chromadb/6c03f27c-dc64-4ecd-aff5-c13bd101e3f7/length.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:44466131cc589c2595a6f2320436bda108bcc206f0dfd06f24a57d9726f41232
|
3 |
+
size 4000
|
Chromadb/6c03f27c-dc64-4ecd-aff5-c13bd101e3f7/link_lists.bin
ADDED
File without changes
|
Chromadb/chroma.sqlite3
ADDED
Binary file (778 kB). View file
|
|
Dockerfile
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
2 |
+
# you will also find guides on how best to write your Dockerfile
|
3 |
+
|
4 |
+
FROM python:3.9
|
5 |
+
|
6 |
+
WORKDIR /code
|
7 |
+
|
8 |
+
COPY ./requirements.txt /code/requirements.txt
|
9 |
+
|
10 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
11 |
+
|
12 |
+
COPY . .
|
13 |
+
|
14 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import fastapi
|
2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
3 |
+
import chromadb
|
4 |
+
from chromadb.utils import embedding_functions
|
5 |
+
from utils import GAMES_DICT
|
6 |
+
|
7 |
+
app = fastapi.FastAPI()
|
8 |
+
|
9 |
+
app.add_middleware(
|
10 |
+
CORSMiddleware,
|
11 |
+
allow_origins=["*"],
|
12 |
+
allow_methods=["*"],
|
13 |
+
allow_headers=["*"],
|
14 |
+
)
|
15 |
+
|
16 |
+
@app.get("/")
|
17 |
+
def hello_world():
|
18 |
+
return {"message": "Hello, World!"}
|
19 |
+
|
20 |
+
@app.get("/{name}/{query}")
|
21 |
+
def hello_world(name: str, query: str):
|
22 |
+
|
23 |
+
if name in GAMES_DICT.keys():
|
24 |
+
chroma_client = chromadb.PersistentClient(path="Chromadb/")
|
25 |
+
SentenceTransformerEmbeddings= embedding_functions.SentenceTransformerEmbeddingFunction(model_name="all-mpnet-base-v2")
|
26 |
+
collection= chroma_client.get_collection("GameMaster", embedding_function=SentenceTransformerEmbeddings)
|
27 |
+
|
28 |
+
results= collection.query(
|
29 |
+
query_texts=[query],
|
30 |
+
n_results=10,
|
31 |
+
where= {"source": GAMES_DICT[name]},
|
32 |
+
include= [ "documents" ]
|
33 |
+
)
|
34 |
+
|
35 |
+
answer= results["documents"][0][0]
|
36 |
+
|
37 |
+
return {"message": answer}
|
38 |
+
|
39 |
+
else:
|
40 |
+
return {"message": "Game not found"}
|
41 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
chromadb
|
3 |
+
sentence_transformers
|
4 |
+
uvicorn
|
utils.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GAMES_DICT= {
|
2 |
+
"EXPLODING KITTENS":"../rules_md/exploding_kittens.md",
|
3 |
+
"CARCASSONE":"../rules_md/carcassone.md",
|
4 |
+
"CATAN":"../rules_md/catan.md"
|
5 |
+
}
|