sharathmajjigi commited on
Commit
46d6d84
·
1 Parent(s): 61ba6a6

Add missing /v1/ground/chat/completions endpoint for Agent-S

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -1,4 +1,3 @@
1
- # app.py - Add Custom Endpoint for Agent-S
2
  import gradio as gr
3
  from transformers import AutoProcessor, AutoModel
4
  import torch
@@ -123,17 +122,18 @@ app.add_middleware(
123
  allow_headers=["*"],
124
  )
125
 
126
- # Custom endpoint specifically for Agent-S
127
- @app.post("/v1/ground")
128
- async def agent_s_grounding(request: Request):
129
  """
130
- Custom endpoint specifically designed for Agent-S
131
  """
132
  try:
133
  # Parse the request body
134
  body = await request.json()
135
 
136
- # Agent-S typically sends data in this format
 
137
  if "data" in body and len(body["data"]) >= 2:
138
  image = body["data"][0] # First element is image
139
  prompt = body["data"][1] # Second element is prompt
@@ -157,21 +157,26 @@ async def agent_s_grounding(request: Request):
157
  content={"error": f"Internal server error: {str(e)}", "status": "failed"}
158
  )
159
 
160
- # Alternative endpoint names for compatibility
 
 
 
 
 
161
  @app.post("/api/ground")
162
  async def api_ground(request: Request):
163
  """Alternative endpoint name for compatibility"""
164
- return await agent_s_grounding(request)
165
 
166
  @app.post("/predict")
167
  async def predict(request: Request):
168
  """Alternative endpoint name for compatibility"""
169
- return await agent_s_grounding(request)
170
 
171
  @app.post("/")
172
  async def root_endpoint(request: Request):
173
  """Root endpoint for compatibility"""
174
- return await agent_s_grounding(request)
175
 
176
  # Create Gradio interface
177
  iface = gr.Interface(
 
 
1
  import gradio as gr
2
  from transformers import AutoProcessor, AutoModel
3
  import torch
 
122
  allow_headers=["*"],
123
  )
124
 
125
+ # CRITICAL: Add the missing endpoint that Agent-S expects
126
+ @app.post("/v1/ground/chat/completions")
127
+ async def chat_completions(request: Request):
128
  """
129
+ Chat completions endpoint that Agent-S expects
130
  """
131
  try:
132
  # Parse the request body
133
  body = await request.json()
134
 
135
+ # Extract image and prompt from the request
136
+ # Agent-S might send data in different formats
137
  if "data" in body and len(body["data"]) >= 2:
138
  image = body["data"][0] # First element is image
139
  prompt = body["data"][1] # Second element is prompt
 
157
  content={"error": f"Internal server error: {str(e)}", "status": "failed"}
158
  )
159
 
160
+ # Keep existing endpoints for compatibility
161
+ @app.post("/v1/ground")
162
+ async def agent_s_grounding(request: Request):
163
+ """Custom endpoint specifically designed for Agent-S"""
164
+ return await chat_completions(request)
165
+
166
  @app.post("/api/ground")
167
  async def api_ground(request: Request):
168
  """Alternative endpoint name for compatibility"""
169
+ return await chat_completions(request)
170
 
171
  @app.post("/predict")
172
  async def predict(request: Request):
173
  """Alternative endpoint name for compatibility"""
174
+ return await chat_completions(request)
175
 
176
  @app.post("/")
177
  async def root_endpoint(request: Request):
178
  """Root endpoint for compatibility"""
179
+ return await chat_completions(request)
180
 
181
  # Create Gradio interface
182
  iface = gr.Interface(