gradio-pr-bot commited on
Commit
a943092
·
verified ·
1 Parent(s): e48b5d1

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +7 -7
  2. requirements.txt +2 -0
  3. run.ipynb +1 -0
  4. run.py +55 -0
README.md CHANGED
@@ -1,12 +1,12 @@
 
1
  ---
2
- title: Server App Main
3
- emoji: 👀
4
- colorFrom: yellow
5
- colorTo: purple
6
  sdk: gradio
7
  sdk_version: 6.9.0
8
- app_file: app.py
9
  pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: server_app_main
4
+ emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 6.9.0
9
+ app_file: run.py
10
  pinned: false
11
+ hf_oauth: true
12
  ---
 
 
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio-client @ git+https://github.com/gradio-app/gradio@305440632cd6ebdc42d5290cbac38569a83a5bdf#subdirectory=client/python
2
+ https://gradio-pypi-previews.s3.amazonaws.com/305440632cd6ebdc42d5290cbac38569a83a5bdf/gradio-6.9.0-py3-none-any.whl
run.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: server_app"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["from gradio import Server\n", "from fastapi.responses import HTMLResponse\n", "\n", "app = Server()\n", "\n", "@app.mcp.tool(name=\"add\")\n", "@app.api(name=\"add\")\n", "def add(a: int, b: int) -> int:\n", " \"\"\"Add two numbers together.\"\"\"\n", " return a + b\n", "\n", "@app.mcp.tool(name=\"multiply\")\n", "@app.api(name=\"multiply\")\n", "def multiply(a: int, b: int) -> int:\n", " \"\"\"Multiply two numbers together.\"\"\"\n", " return a * b\n", "\n", "@app.get(\"/\", response_class=HTMLResponse)\n", "async def homepage():\n", " return \"\"\"\n", "<!DOCTYPE html>\n", "<html>\n", "<head><title>Calculator</title>\n", "<style>\n", " * { margin: 0; box-sizing: border-box; font-family: 'Courier New', monospace; }\n", " body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #1a1a2e; color: #fff;}\n", " .calc { background: #16213e; padding: 2rem; border-radius: 1rem; box-shadow: 0 8px 32px rgba(0,0,0,.4); width: 320px; }\n", " #out { background: #0f3460; color: #0f0; font-size: 2rem; text-align: right; padding: .75rem 1rem; border-radius: .5rem; min-height: 3rem; margin-bottom: 1rem; }\n", " .row { display: flex; gap: .5rem; margin-bottom: .5rem; }\n", " input { flex: 1; min-width: 0; padding: .6rem; font-size: 1.2rem; border: none; border-radius: .5rem; background: #e2e2e2; text-align: center; }\n", " button { flex: 1; padding: .6rem; font-size: 1rem; border: none; border-radius: .5rem; cursor: pointer; font-weight: bold; color: #fff; }\n", " .add { background: #e94560; } .mul { background: #533483; }\n", " button:hover { opacity: .85; }\n", "</style></head>\n", "<body>\n", " <div class=\"calc\">\n", " <div id=\"out\">0</div>\n", " Operands\n", " <div class=\"row\"><input id=\"a\" type=\"number\" value=\"3\"><input id=\"b\" type=\"number\" value=\"5\"></div>\n", " Operation\n", " <div class=\"row\"><button class=\"add\" onclick=\"run('add')\">+</button><button class=\"mul\" onclick=\"run('multiply')\">&times;</button></div>\n", " </div>\n", " <script type=\"module\">\n", " import { client } from \"https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.min.js\";\n", " const app = await client(location.origin);\n", " window.run = async (ep) => {\n", " const a = parseInt(document.getElementById(\"a\").value), b = parseInt(document.getElementById(\"b\").value);\n", " document.getElementById(\"out\").textContent = (await app.predict(\"/\" + ep, { a, b })).data;\n", " };\n", " </script>\n", "</body>\n", "</html>\"\"\"\n", "\n", "if __name__ == \"__main__\":\n", " app.launch(mcp_server=True)\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gradio import Server
2
+ from fastapi.responses import HTMLResponse
3
+
4
+ app = Server()
5
+
6
+ @app.mcp.tool(name="add")
7
+ @app.api(name="add")
8
+ def add(a: int, b: int) -> int:
9
+ """Add two numbers together."""
10
+ return a + b
11
+
12
+ @app.mcp.tool(name="multiply")
13
+ @app.api(name="multiply")
14
+ def multiply(a: int, b: int) -> int:
15
+ """Multiply two numbers together."""
16
+ return a * b
17
+
18
+ @app.get("/", response_class=HTMLResponse)
19
+ async def homepage():
20
+ return """
21
+ <!DOCTYPE html>
22
+ <html>
23
+ <head><title>Calculator</title>
24
+ <style>
25
+ * { margin: 0; box-sizing: border-box; font-family: 'Courier New', monospace; }
26
+ body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #1a1a2e; color: #fff;}
27
+ .calc { background: #16213e; padding: 2rem; border-radius: 1rem; box-shadow: 0 8px 32px rgba(0,0,0,.4); width: 320px; }
28
+ #out { background: #0f3460; color: #0f0; font-size: 2rem; text-align: right; padding: .75rem 1rem; border-radius: .5rem; min-height: 3rem; margin-bottom: 1rem; }
29
+ .row { display: flex; gap: .5rem; margin-bottom: .5rem; }
30
+ input { flex: 1; min-width: 0; padding: .6rem; font-size: 1.2rem; border: none; border-radius: .5rem; background: #e2e2e2; text-align: center; }
31
+ button { flex: 1; padding: .6rem; font-size: 1rem; border: none; border-radius: .5rem; cursor: pointer; font-weight: bold; color: #fff; }
32
+ .add { background: #e94560; } .mul { background: #533483; }
33
+ button:hover { opacity: .85; }
34
+ </style></head>
35
+ <body>
36
+ <div class="calc">
37
+ <div id="out">0</div>
38
+ Operands
39
+ <div class="row"><input id="a" type="number" value="3"><input id="b" type="number" value="5"></div>
40
+ Operation
41
+ <div class="row"><button class="add" onclick="run('add')">+</button><button class="mul" onclick="run('multiply')">&times;</button></div>
42
+ </div>
43
+ <script type="module">
44
+ import { client } from "https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.min.js";
45
+ const app = await client(location.origin);
46
+ window.run = async (ep) => {
47
+ const a = parseInt(document.getElementById("a").value), b = parseInt(document.getElementById("b").value);
48
+ document.getElementById("out").textContent = (await app.predict("/" + ep, { a, b })).data;
49
+ };
50
+ </script>
51
+ </body>
52
+ </html>"""
53
+
54
+ if __name__ == "__main__":
55
+ app.launch(mcp_server=True)