Mousiol commited on
Commit
675b773
·
verified ·
1 Parent(s): 1569dc0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -125,7 +125,9 @@ demo = gr.TabbedInterface(
125
  # Launch Gradio non-blocking on port 7860
126
  demo.launch(prevent_thread_lock=True)
127
 
128
- # 7. FastAPI Schemas & Custom Endpoints attached to demo.app
 
 
129
  class EmbedRequest(BaseModel):
130
  input: Union[str, List[str]]
131
  input_type: Optional[str] = "document"
@@ -143,7 +145,7 @@ def extract_token(authorization: Optional[str], x_api_key: Optional[str]) -> Opt
143
  return authorization[7:].strip()
144
  return None
145
 
146
- @demo.app.get("/health")
147
  def health_check():
148
  return {
149
  "status": "online",
@@ -151,7 +153,7 @@ def health_check():
151
  "endpoints": ["/v1/embeddings", "/v1/systemone", "/v1/decide"]
152
  }
153
 
154
- @demo.app.post("/v1/embeddings")
155
  def create_embeddings(
156
  req: EmbedRequest,
157
  authorization: Optional[str] = Header(default=None),
@@ -167,8 +169,8 @@ def create_embeddings(
167
  "data": data
168
  }
169
 
170
- @demo.app.post("/v1/systemone")
171
- @demo.app.post("/v1/decide")
172
  def create_decision(
173
  req: DecisionRequest,
174
  authorization: Optional[str] = Header(default=None),
@@ -179,4 +181,7 @@ def create_decision(
179
 
180
  return compute_decision(token, req.state, req.questions)
181
 
 
 
 
182
  demo.block_thread()
 
125
  # Launch Gradio non-blocking on port 7860
126
  demo.launch(prevent_thread_lock=True)
127
 
128
+ # 7. Create an APIRouter for custom endpoints
129
+ api_router = APIRouter()
130
+
131
  class EmbedRequest(BaseModel):
132
  input: Union[str, List[str]]
133
  input_type: Optional[str] = "document"
 
145
  return authorization[7:].strip()
146
  return None
147
 
148
+ @api_router.get("/health")
149
  def health_check():
150
  return {
151
  "status": "online",
 
153
  "endpoints": ["/v1/embeddings", "/v1/systemone", "/v1/decide"]
154
  }
155
 
156
+ @api_router.post("/v1/embeddings")
157
  def create_embeddings(
158
  req: EmbedRequest,
159
  authorization: Optional[str] = Header(default=None),
 
169
  "data": data
170
  }
171
 
172
+ @api_router.post("/v1/systemone")
173
+ @api_router.post("/v1/decide")
174
  def create_decision(
175
  req: DecisionRequest,
176
  authorization: Optional[str] = Header(default=None),
 
181
 
182
  return compute_decision(token, req.state, req.questions)
183
 
184
+ # Prepend custom routes BEFORE Gradio's catch-all GET /{path:path} route
185
+ demo.app.router.routes = api_router.routes + demo.app.router.routes
186
+
187
  demo.block_thread()