Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ app = FastAPI(
|
|
11 |
description="Find relevant technologies from a problem",
|
12 |
)
|
13 |
|
14 |
-
class
|
15 |
problem: str
|
16 |
|
17 |
class InputConstraints(BaseModel):
|
@@ -27,37 +27,47 @@ class Technology(BaseModel):
|
|
27 |
limitations: str
|
28 |
id: int
|
29 |
|
30 |
-
class
|
31 |
"""Represents the search of prior art using the technology combinations"""
|
32 |
content: str
|
33 |
uris: List
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
# This schema defines the root structure of the JSON
|
36 |
class TechnologyData(BaseModel):
|
37 |
"""Represents the top-level object containing a list of technologies."""
|
38 |
technologies: List[Technology]
|
39 |
|
40 |
@app.post("/process", response_model=TechnologyData)
|
41 |
-
async def process(data:
|
42 |
-
result = process_input(data, global_tech, global_tech_embeddings, "problem")
|
43 |
-
return {"technologies": result}
|
44 |
|
45 |
@app.post("/process-constraints", response_model=TechnologyData)
|
46 |
async def process_constraints(constraints: InputConstraints):
|
47 |
-
result = process_input(constraints.constraints, global_tech, global_tech_embeddings, "constraints")
|
48 |
-
return {"technologies": result}
|
49 |
|
50 |
-
@app.post("/prior-art-constraints", response_model=
|
51 |
-
async def prior_art_search(
|
52 |
-
prior_art = process_prior_art(
|
53 |
return prior_art
|
54 |
|
55 |
-
@app.post("/prior-art-problems", response_model=
|
56 |
-
async def
|
57 |
-
prior_art = process_prior_art(technologies, problems,
|
58 |
return prior_art
|
59 |
|
60 |
-
|
61 |
def make_json_serializable(data):
|
62 |
if isinstance(data, dict):
|
63 |
return {k: make_json_serializable(v) for k, v in data.items()}
|
|
|
11 |
description="Find relevant technologies from a problem",
|
12 |
)
|
13 |
|
14 |
+
class InputProblem(BaseModel):
|
15 |
problem: str
|
16 |
|
17 |
class InputConstraints(BaseModel):
|
|
|
27 |
limitations: str
|
28 |
id: int
|
29 |
|
30 |
+
class OutputPriorArt(BaseModel):
|
31 |
"""Represents the search of prior art using the technology combinations"""
|
32 |
content: str
|
33 |
uris: List
|
34 |
|
35 |
+
class InputPriorArtConstraints(BaseModel):
|
36 |
+
technologies: List[Technology]
|
37 |
+
constriants: List[InputConstraints]
|
38 |
+
data_type: str
|
39 |
+
|
40 |
+
class InputPriorArtProblems(BaseModel):
|
41 |
+
technologies: List[Technology]
|
42 |
+
constriants: List[InputProblem]
|
43 |
+
data_type: str
|
44 |
+
|
45 |
+
|
46 |
# This schema defines the root structure of the JSON
|
47 |
class TechnologyData(BaseModel):
|
48 |
"""Represents the top-level object containing a list of technologies."""
|
49 |
technologies: List[Technology]
|
50 |
|
51 |
@app.post("/process", response_model=TechnologyData)
|
52 |
+
async def process(data: InputProblem):
|
53 |
+
result, prior_art = process_input(data, global_tech, global_tech_embeddings, "problem")
|
54 |
+
return {"technologies": result, "prior_art": prior_art}
|
55 |
|
56 |
@app.post("/process-constraints", response_model=TechnologyData)
|
57 |
async def process_constraints(constraints: InputConstraints):
|
58 |
+
result, prior_art = process_input(constraints.constraints, global_tech, global_tech_embeddings, "constraints")
|
59 |
+
return {"technologies": result, "prior_art": prior_art}
|
60 |
|
61 |
+
@app.post("/prior-art-constraints", response_model=OutputPriorArt)
|
62 |
+
async def prior_art_search(data: InputPriorArtConstraints):
|
63 |
+
prior_art = process_prior_art(InputPriorArtConstraints.technologies, InputPriorArtConstraints.constriants, InputPriorArtConstraints.data_type)
|
64 |
return prior_art
|
65 |
|
66 |
+
@app.post("/prior-art-problems", response_model=OutputPriorArt)
|
67 |
+
async def prior_art_search(data: InputPriorArtProblems):
|
68 |
+
prior_art = process_prior_art(InputPriorArtProblems.technologies, InputPriorArtProblems.problems, InputPriorArtProblems.data_type)
|
69 |
return prior_art
|
70 |
|
|
|
71 |
def make_json_serializable(data):
|
72 |
if isinstance(data, dict):
|
73 |
return {k: make_json_serializable(v) for k, v in data.items()}
|