Spaces:
Build error
Build error
Upload server.py
Browse files
server.py
CHANGED
@@ -39,31 +39,6 @@ def get_embedding_function():
|
|
39 |
return embeddings
|
40 |
|
41 |
|
42 |
-
@app.get("/")
|
43 |
-
def greet_json():
|
44 |
-
return {"Hello": "World!"}
|
45 |
-
|
46 |
-
|
47 |
-
class QueryRequest(BaseModel):
|
48 |
-
query_text: str
|
49 |
-
|
50 |
-
|
51 |
-
@app.get("/train")
|
52 |
-
def train():
|
53 |
-
|
54 |
-
# Check if the database should be cleared (using the --clear flag).
|
55 |
-
parser = argparse.ArgumentParser()
|
56 |
-
parser.add_argument("--reset", action="store_true", help="Reset the database.")
|
57 |
-
args = parser.parse_args()
|
58 |
-
if args.reset:
|
59 |
-
print("✨ Clearing Database")
|
60 |
-
clear_database()
|
61 |
-
|
62 |
-
# Create (or update) the data store.
|
63 |
-
documents = load_documents()
|
64 |
-
chunks = split_documents(documents)
|
65 |
-
add_to_chroma(chunks)
|
66 |
-
|
67 |
|
68 |
def load_documents():
|
69 |
document_loader = PyPDFDirectoryLoader(DATA_PATH)
|
@@ -145,6 +120,35 @@ def clear_database():
|
|
145 |
return {""}
|
146 |
|
147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
@app.get("/query")
|
149 |
def query(request: QueryRequest):
|
150 |
query_text = request.query_text
|
@@ -168,17 +172,3 @@ def query(request: QueryRequest):
|
|
168 |
print(formatted_response)
|
169 |
return response_text
|
170 |
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
|
|
39 |
return embeddings
|
40 |
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
def load_documents():
|
44 |
document_loader = PyPDFDirectoryLoader(DATA_PATH)
|
|
|
120 |
return {""}
|
121 |
|
122 |
|
123 |
+
|
124 |
+
@app.get("/")
|
125 |
+
def greet_json():
|
126 |
+
return {"Hello": "World!"}
|
127 |
+
|
128 |
+
|
129 |
+
class QueryRequest(BaseModel):
|
130 |
+
query_text: str
|
131 |
+
|
132 |
+
|
133 |
+
@app.get("/train")
|
134 |
+
def train():
|
135 |
+
|
136 |
+
# Check if the database should be cleared (using the --clear flag).
|
137 |
+
parser = argparse.ArgumentParser()
|
138 |
+
parser.add_argument("--reset", action="store_true", help="Reset the database.")
|
139 |
+
args = parser.parse_args()
|
140 |
+
if args.reset:
|
141 |
+
print("✨ Clearing Database")
|
142 |
+
clear_database()
|
143 |
+
|
144 |
+
# Create (or update) the data store.
|
145 |
+
documents = load_documents()
|
146 |
+
chunks = split_documents(documents)
|
147 |
+
add_to_chroma(chunks)
|
148 |
+
|
149 |
+
|
150 |
+
|
151 |
+
|
152 |
@app.get("/query")
|
153 |
def query(request: QueryRequest):
|
154 |
query_text = request.query_text
|
|
|
172 |
print(formatted_response)
|
173 |
return response_text
|
174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|