Spaces:
Sleeping
Sleeping
Lazar Radojevic
commited on
Commit
·
ef34e97
1
Parent(s):
c212d1a
test
Browse files
README.md
CHANGED
@@ -6,6 +6,7 @@ colorTo: green
|
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
license: apache-2.0
|
|
|
9 |
---
|
10 |
|
11 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
license: apache-2.0
|
9 |
+
app_file: run.py
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
main.py
CHANGED
@@ -1,54 +1,28 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
-
from
|
3 |
-
from typing import List
|
4 |
-
from src.search_engine import PromptSearchEngine
|
5 |
-
from src.prompt_loader import PromptLoader
|
6 |
|
7 |
-
|
8 |
-
SEED = 42
|
9 |
-
DATA_SIZE = 100
|
10 |
|
11 |
-
# Initialize the prompt loader and search engine
|
12 |
-
prompts = PromptLoader(seed=SEED).load_data(size=DATA_SIZE)
|
13 |
-
engine = PromptSearchEngine(prompts)
|
14 |
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
n: int = 5
|
23 |
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
prompt
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
@app.get("/")
|
35 |
-
def read_root():
|
36 |
-
return {"message": "Hello, FastAPI!"}
|
37 |
-
|
38 |
-
|
39 |
-
# API endpoint
|
40 |
-
@app.post("/most_similar", response_model=QueryResponse)
|
41 |
-
async def get_most_similar(query_request: QueryRequest):
|
42 |
-
try:
|
43 |
-
similar_prompts = engine.most_similar(
|
44 |
-
query=query_request.query, n=query_request.n
|
45 |
-
)
|
46 |
-
response = QueryResponse(
|
47 |
-
similar_prompts=[
|
48 |
-
SimilarPrompt(score=score, prompt=prompt)
|
49 |
-
for score, prompt in similar_prompts
|
50 |
-
]
|
51 |
-
)
|
52 |
-
return response
|
53 |
-
except Exception as e:
|
54 |
-
raise HTTPException(status_code=500, detail=str(e))
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
3 |
|
4 |
+
app = FastAPI(title="Deploying FastAPI Apps on Huggingface")
|
|
|
|
|
5 |
|
|
|
|
|
|
|
6 |
|
7 |
+
app.add_middleware(
|
8 |
+
CORSMiddleware,
|
9 |
+
allow_origins=["*"],
|
10 |
+
allow_credentials=True,
|
11 |
+
allow_methods=["*"],
|
12 |
+
allow_headers=["*"],
|
13 |
+
)
|
14 |
|
15 |
|
16 |
+
@app.get("/", tags=["Home"])
|
17 |
+
def api_home():
|
18 |
+
return {"detail": "Welcome to FastAPI TextGen Tutorial!"}
|
|
|
19 |
|
20 |
|
21 |
+
@app.post(
|
22 |
+
"/api/generate",
|
23 |
+
summary="Generate text from prompt",
|
24 |
+
tags=["Generate"],
|
25 |
+
response_model=Generate,
|
26 |
+
)
|
27 |
+
def inference(input_prompt: str):
|
28 |
+
return "Hello"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|