OppaAI commited on
Commit
d598663
·
verified ·
1 Parent(s): 906625a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -12
app.py CHANGED
@@ -77,10 +77,7 @@ def safe_parse_json_from_text(text: str):
77
  # ---------------------------------------------------
78
  # TRUE MCP TOOL — THIS must be exposed to MCP client
79
  # ---------------------------------------------------
80
- @mcp.tool(
81
- name="robot_watch",
82
- description="Analyze a base64 image using Qwen VLM and return structured JSON.",
83
- )
84
  def robot_watch(payload: RobotWatchPayload): # <-- Type hint with Pydantic model
85
  # The payload is already validated and typed correctly by fastmcp/pydantic
86
  hf_token = payload.hf_token
@@ -139,17 +136,15 @@ Respond in STRICT JSON ONLY:
139
 
140
 
141
  # ---------------------------------------------------
142
- # Gradio UI — separate from MCP tool layer
143
  # ---------------------------------------------------
144
- # The process_json function will still work with the Pydantic model input
145
- def process_json(payload: Dict[str, Any]):
146
- # When called via Gradio UI (not MCP), input will be Dict, so handle type conversion
147
- pydantic_payload = RobotWatchPayload(**payload)
148
- return robot_watch(pydantic_payload)
149
 
150
 
151
  app = gr.Interface(
152
- fn=process_json,
153
  inputs=gr.JSON(),
154
  outputs=gr.JSON(),
155
  title="Robot MCP Server",
@@ -157,5 +152,5 @@ app = gr.Interface(
157
  )
158
 
159
  if __name__ == "__main__":
160
- # Gradio will use the 'mcp' instance defined globally to host the MCP server endpoints
161
  app.launch(mcp_server=True)
 
77
  # ---------------------------------------------------
78
  # TRUE MCP TOOL — THIS must be exposed to MCP client
79
  # ---------------------------------------------------
80
+ @mcp.api("/robot_watch", description="Analyze a base64 image using Qwen VLM and return structured JSON.")
 
 
 
81
  def robot_watch(payload: RobotWatchPayload): # <-- Type hint with Pydantic model
82
  # The payload is already validated and typed correctly by fastmcp/pydantic
83
  hf_token = payload.hf_token
 
136
 
137
 
138
  # ---------------------------------------------------
139
+ # Gradio UI — Use a simple placeholder function for the UI
140
  # ---------------------------------------------------
141
+ def gradio_placeholder(payload):
142
+ # This is just for the interactive UI, the real API call goes to /robot_watch endpoint
143
+ return {"message": "Use the MCP Client to call the robot_watch tool."}
 
 
144
 
145
 
146
  app = gr.Interface(
147
+ fn=gradio_placeholder,
148
  inputs=gr.JSON(),
149
  outputs=gr.JSON(),
150
  title="Robot MCP Server",
 
152
  )
153
 
154
  if __name__ == "__main__":
155
+ # Launch Gradio, which automatically hooks up the 'mcp' instance's APIs
156
  app.launch(mcp_server=True)