HimanshuGoyal2004 commited on
Commit
f54375b
Β·
1 Parent(s): a9142dd

refactor: simplify Gradio interface creation for GitHub MCP Server

Browse files
Files changed (1) hide show
  1. app.py +46 -67
app.py CHANGED
@@ -1,8 +1,3 @@
1
- """
2
- GitHub MCP Server with Gradio Interface
3
- Provides GitHub repository scanning and file content access via MCP
4
- """
5
-
6
  import json
7
  import os
8
  import base64
@@ -144,68 +139,52 @@ class GitHubMCPServer:
144
  # Initialize the GitHub MCP server
145
  github_server = GitHubMCPServer()
146
 
147
- # Create Gradio interface
148
- with gr.Blocks(title="GitHub MCP Server", theme=gr.themes.Soft()) as demo:
149
- gr.Markdown("# πŸ™ GitHub MCP Server")
150
- gr.Markdown("Access GitHub repositories via Model Context Protocol")
151
-
152
- with gr.Tabs():
153
- with gr.Tab("Repository Info"):
154
- gr.Markdown("### Get Repository Information")
155
- with gr.Row():
156
- repo_owner = gr.Textbox(label="Repository Owner", placeholder="octocat")
157
- repo_name = gr.Textbox(label="Repository Name", placeholder="Hello-World")
158
-
159
- repo_info_btn = gr.Button("Get Repository Info", variant="primary")
160
- repo_info_output = gr.Textbox(label="Repository Information", lines=15)
161
-
162
- repo_info_btn.click(
163
- fn=github_server.get_repository_info,
164
- inputs=[repo_owner, repo_name],
165
- outputs=repo_info_output
166
- )
167
-
168
- with gr.Tab("File Content"):
169
- gr.Markdown("### Get File Content")
170
- with gr.Row():
171
- file_owner = gr.Textbox(label="Repository Owner", placeholder="octocat")
172
- file_repo = gr.Textbox(label="Repository Name", placeholder="Hello-World")
173
-
174
- file_path = gr.Textbox(label="File Path", placeholder="README.md")
175
-
176
- file_content_btn = gr.Button("Get File Content", variant="primary")
177
- file_content_output = gr.Textbox(label="File Content", lines=20)
178
-
179
- file_content_btn.click(
180
- fn=github_server.get_file_content,
181
- inputs=[file_owner, file_repo, file_path],
182
- outputs=file_content_output
183
- )
184
-
185
- with gr.Tab("Repository Scanner"):
186
- gr.Markdown("### Scan Repository for Code Files")
187
- with gr.Row():
188
- scan_owner = gr.Textbox(label="Repository Owner", placeholder="octocat")
189
- scan_repo = gr.Textbox(label="Repository Name", placeholder="Hello-World")
190
-
191
- scan_extensions = gr.Textbox(
192
- label="File Extensions",
193
- value=".py,.js,.ts,.php,.java",
194
- placeholder=".py,.js,.ts,.php,.java"
195
- )
196
-
197
- scan_btn = gr.Button("Scan Repository", variant="primary")
198
- scan_output = gr.Textbox(label="Scan Results", lines=20)
199
-
200
- scan_btn.click(
201
- fn=github_server.scan_repository,
202
- inputs=[scan_owner, scan_repo, scan_extensions],
203
- outputs=scan_output
204
- )
205
-
206
- gr.Markdown("---")
207
- gr.Markdown("πŸ’‘ **Setup**: Add your `GITHUB_TOKEN` to environment variables or `.env` file")
208
- gr.Markdown("πŸš€ **Deploy**: This server can be deployed on Hugging Face Spaces with MCP support")
209
 
210
  if __name__ == "__main__":
211
  print("πŸš€ Starting GitHub MCP Server with Gradio...")
 
 
 
 
 
 
1
  import json
2
  import os
3
  import base64
 
139
  # Initialize the GitHub MCP server
140
  github_server = GitHubMCPServer()
141
 
142
+ # Create Gradio interfaces for MCP
143
+ demo = gr.TabbedInterface(
144
+ [
145
+ gr.Interface(
146
+ fn=github_server.get_repository_info,
147
+ inputs=[
148
+ gr.Textbox(label="Repository Owner", placeholder="octocat"),
149
+ gr.Textbox(label="Repository Name", placeholder="Hello-World")
150
+ ],
151
+ outputs=gr.Textbox(label="Repository Information", lines=15),
152
+ title="Get Repository Information",
153
+ description="Get basic information about a GitHub repository",
154
+ api_name="get_repository_info"
155
+ ),
156
+ gr.Interface(
157
+ fn=github_server.get_file_content,
158
+ inputs=[
159
+ gr.Textbox(label="Repository Owner", placeholder="octocat"),
160
+ gr.Textbox(label="Repository Name", placeholder="Hello-World"),
161
+ gr.Textbox(label="File Path", placeholder="README.md")
162
+ ],
163
+ outputs=gr.Textbox(label="File Content", lines=20),
164
+ title="Get File Content",
165
+ description="Get the content of a specific file from a GitHub repository",
166
+ api_name="get_file_content"
167
+ ),
168
+ gr.Interface(
169
+ fn=github_server.scan_repository,
170
+ inputs=[
171
+ gr.Textbox(label="Repository Owner", placeholder="octocat"),
172
+ gr.Textbox(label="Repository Name", placeholder="Hello-World"),
173
+ gr.Textbox(label="File Extensions", value=".py,.js,.ts,.php,.java", placeholder=".py,.js,.ts,.php,.java")
174
+ ],
175
+ outputs=gr.Textbox(label="Scan Results", lines=20),
176
+ title="Scan Repository for Code Files",
177
+ description="Scan a GitHub repository for code files with specified extensions",
178
+ api_name="scan_repository"
179
+ )
180
+ ],
181
+ [
182
+ "Repository Info",
183
+ "File Content",
184
+ "Repository Scanner"
185
+ ],
186
+ title="πŸ™ GitHub MCP Server"
187
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
 
189
  if __name__ == "__main__":
190
  print("πŸš€ Starting GitHub MCP Server with Gradio...")