Vladt-Tempest commited on
Commit
4bdd2e5
·
1 Parent(s): 35dcde9

Code Explanation

Browse files
Files changed (1) hide show
  1. app.py +26 -1
app.py CHANGED
@@ -34,4 +34,29 @@ demo = gr.Interface(
34
 
35
  # Launch the interface and MCP server
36
  if __name__ == "__main__":
37
- demo.launch(mcp_server=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  # Launch the interface and MCP server
36
  if __name__ == "__main__":
37
+ demo.launch(mcp_server=True)
38
+
39
+ """Understanding the Code
40
+ Let’s break down the key components:
41
+
42
+ 1. Function Definition:
43
+
44
+ The sentiment_analysis function takes a text input and returns a dictionary
45
+ It uses TextBlob to analyze the sentiment
46
+ The docstring is crucial as it helps Gradio generate the MCP tool schema
47
+ Type hints (str and dict) help define the input/output schema
48
+
49
+ 2. Gradio Interface:
50
+
51
+ gr.Interface creates both the web UI and MCP server
52
+ The function is exposed as an MCP tool automatically
53
+ Input and output components define the tool’s schema
54
+ The JSON output component ensures proper serialization
55
+
56
+ 3. MCP Server:
57
+
58
+ Setting mcp_server=True enables the MCP server
59
+ The server will be available at http://localhost:7860/gradio_api/mcp/sse
60
+ You can also enable it using the environment variable:
61
+ Copied
62
+ """