milwright commited on
Commit
b55cd16
·
verified ·
1 Parent(s): b1f7185

Delete gradio_docs.py

Browse files
Files changed (1) hide show
  1. gradio_docs.py +0 -109
gradio_docs.py DELETED
@@ -1,109 +0,0 @@
1
- """
2
- Gradio Documentation MCP Server Integration
3
-
4
- DEVELOPMENT ONLY - DO NOT IMPORT IN MAIN APPLICATION
5
-
6
- This module provides access to live Gradio documentation via MCP server
7
- for local development assistance. It should NOT be imported in app.py or
8
- support_docs.py as it's not needed for the deployed application.
9
-
10
- Usage:
11
- python -c "from gradio_docs import gradio_docs; print(gradio_docs.search_docs('ChatInterface'))"
12
- """
13
-
14
- import requests
15
- import json
16
- from typing import Optional, Dict, Any
17
-
18
- class GradioDocsClient:
19
- """Client for accessing Gradio documentation via MCP server"""
20
-
21
- def __init__(self, base_url: str = "https://gradio-docs-mcp.hf.space"):
22
- self.base_url = base_url.rstrip('/')
23
- self.session = requests.Session()
24
- self.session.headers.update({
25
- 'User-Agent': 'ChatUI-Helper/1.0'
26
- })
27
-
28
- def search_docs(self, query: str, limit: int = 5) -> Optional[Dict[str, Any]]:
29
- """
30
- Search Gradio documentation for relevant information
31
-
32
- Args:
33
- query: Search query string
34
- limit: Maximum number of results to return
35
-
36
- Returns:
37
- Dictionary with search results or None if error
38
- """
39
- try:
40
- # Try to use the API endpoint for search
41
- search_url = f"{self.base_url}/gradio_api"
42
-
43
- response = self.session.post(
44
- search_url,
45
- json={"query": query, "limit": limit},
46
- timeout=10
47
- )
48
-
49
- if response.status_code == 200:
50
- return response.json()
51
- else:
52
- print(f"Gradio docs search failed: {response.status_code}")
53
- return None
54
-
55
- except requests.RequestException as e:
56
- print(f"Error connecting to Gradio docs server: {e}")
57
- return None
58
-
59
- def get_component_info(self, component_name: str) -> Optional[str]:
60
- """
61
- Get information about a specific Gradio component
62
-
63
- Args:
64
- component_name: Name of the Gradio component (e.g., 'ChatInterface', 'Textbox')
65
-
66
- Returns:
67
- Documentation string or None if not found
68
- """
69
- result = self.search_docs(f"gr.{component_name}")
70
- if result and "results" in result:
71
- # Extract relevant documentation from results
72
- docs = []
73
- for item in result["results"][:3]: # Top 3 results
74
- if "content" in item:
75
- docs.append(item["content"])
76
- return "\n\n".join(docs) if docs else None
77
- return None
78
-
79
- def get_latest_changes(self) -> Optional[str]:
80
- """
81
- Get information about latest Gradio changes and updates
82
-
83
- Returns:
84
- Latest changes information or None if not available
85
- """
86
- result = self.search_docs("changelog updates latest version")
87
- if result and "results" in result:
88
- changes = []
89
- for item in result["results"][:2]: # Top 2 results
90
- if "content" in item:
91
- changes.append(item["content"])
92
- return "\n\n".join(changes) if changes else None
93
- return None
94
-
95
- def is_available(self) -> bool:
96
- """
97
- Check if the Gradio docs server is available
98
-
99
- Returns:
100
- True if server is accessible, False otherwise
101
- """
102
- try:
103
- response = self.session.get(self.base_url, timeout=5)
104
- return response.status_code == 200
105
- except requests.RequestException:
106
- return False
107
-
108
- # Global instance for easy access
109
- gradio_docs = GradioDocsClient()