Spaces:
Sleeping
Sleeping
Inital commit
Browse files- .gitignore +12 -0
- app.py +116 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Python-generated files
|
2 |
+
__pycache__/
|
3 |
+
*.py[oc]
|
4 |
+
build/
|
5 |
+
dist/
|
6 |
+
wheels/
|
7 |
+
*.egg-info
|
8 |
+
|
9 |
+
# Virtual environments
|
10 |
+
.venv
|
11 |
+
.env
|
12 |
+
|
app.py
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from mcp.server.fastmcp import FastMCP
|
4 |
+
import webbrowser
|
5 |
+
import urllib.parse
|
6 |
+
from datetime import datetime
|
7 |
+
import json
|
8 |
+
|
9 |
+
# Create an MCP server
|
10 |
+
mcp = FastMCP("Cypress")
|
11 |
+
|
12 |
+
|
13 |
+
# Add tool
|
14 |
+
@mcp.tool()
|
15 |
+
def google_search(query):
|
16 |
+
"""Search in google with query."""
|
17 |
+
encoded_query = urllib.parse.quote_plus(query)
|
18 |
+
url = f"https:///www.google.com/search?q={encoded_query}"
|
19 |
+
webbrowser.open(url)
|
20 |
+
|
21 |
+
|
22 |
+
# Add tool
|
23 |
+
@mcp.tool()
|
24 |
+
def add(a: int, b: int)-> int:
|
25 |
+
"""Add two numbers."""
|
26 |
+
return a + b
|
27 |
+
|
28 |
+
|
29 |
+
# Add a dynamic greeting resource
|
30 |
+
@mcp.resource("greeing://{name}")
|
31 |
+
def get_greeting(name: str) -> str:
|
32 |
+
"""Get a personalized greeting."""
|
33 |
+
return f"Hello, {name}!"
|
34 |
+
|
35 |
+
# Resources
|
36 |
+
@mcp.resource("resource://server-status")
|
37 |
+
def get_server_status() -> dict:
|
38 |
+
"""Get current server status information."""
|
39 |
+
return {
|
40 |
+
"status": "running",
|
41 |
+
"timestamp": datetime.now().isoformat(),
|
42 |
+
"version": "0.1.0",
|
43 |
+
"features": ["tools", "resources", "prompts"]
|
44 |
+
}
|
45 |
+
|
46 |
+
|
47 |
+
# Add a prompt
|
48 |
+
@mcp.prompt()
|
49 |
+
def explain_concept_prompt(concept: str, audience: str = "general") -> str:
|
50 |
+
"""Generate a prompt to explain a technical concept to a specific audience."""
|
51 |
+
audience_instructions = {
|
52 |
+
"beginner": "Use simple language, avoid jargon, and provide relatable analogies",
|
53 |
+
"intermediate": "Use technical terms but explain them, provide examples",
|
54 |
+
"expert": "Use precise technical language and focus on nuances",
|
55 |
+
"general": "Use accesible language with some technical detail"
|
56 |
+
}
|
57 |
+
|
58 |
+
instruction = audience_instructions.get(audience, audience_instructions["general"])
|
59 |
+
return f"""Explain the concept of '{concept}' to a {audience} audience.
|
60 |
+
|
61 |
+
Guidelines: {instruction}
|
62 |
+
|
63 |
+
Structure your explanation with:
|
64 |
+
1. A brief overview
|
65 |
+
2. Key components or aspects
|
66 |
+
3. Practical examples or use cases
|
67 |
+
4. Common misconceptions (if any)
|
68 |
+
5. Further learning resources"""
|
69 |
+
|
70 |
+
|
71 |
+
demo = gr.TabbedInterface(
|
72 |
+
[
|
73 |
+
gr.Interface(
|
74 |
+
get_greeting,
|
75 |
+
gr.Textbox(),
|
76 |
+
gr.Textbox(),
|
77 |
+
api_name="get_greeting"
|
78 |
+
),
|
79 |
+
gr.Interface(
|
80 |
+
add,
|
81 |
+
gr.Textbox(),
|
82 |
+
gr.Textbox(),
|
83 |
+
api_name="add"
|
84 |
+
),
|
85 |
+
gr.Interface(
|
86 |
+
explain_concept_prompt,
|
87 |
+
gr.Textbox(),
|
88 |
+
gr.Textbox(),
|
89 |
+
api_name="explain_concept_prompt"
|
90 |
+
),
|
91 |
+
gr.Interface(
|
92 |
+
google_search,
|
93 |
+
gr.Textbox(),
|
94 |
+
gr.Textbox(),
|
95 |
+
api_name="google_search"
|
96 |
+
),
|
97 |
+
gr.Interface(
|
98 |
+
get_server_status,
|
99 |
+
gr.Textbox(),
|
100 |
+
gr.Textbox(),
|
101 |
+
api_name="get_server_status"
|
102 |
+
)
|
103 |
+
|
104 |
+
|
105 |
+
],
|
106 |
+
[
|
107 |
+
"Get Greeting",
|
108 |
+
"Add",
|
109 |
+
"Explain Concept Prompt",
|
110 |
+
"Google Search",
|
111 |
+
"Get Server Status"
|
112 |
+
]
|
113 |
+
)
|
114 |
+
|
115 |
+
if __name__ == "__main__":
|
116 |
+
demo.launch(mcp_server=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
"gradio[cli]"
|
2 |
+
"mcp[cli]"
|