Yoon-gu Hwang
commited on
Commit
·
af9d55b
1
Parent(s):
1314c33
multiple apis and ui in a mcp server
Browse files
app.py
CHANGED
@@ -1,37 +1,83 @@
|
|
1 |
-
import
|
2 |
import gradio as gr
|
3 |
-
from
|
|
|
|
|
4 |
|
5 |
-
def
|
6 |
"""
|
7 |
-
|
8 |
|
9 |
Args:
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
Returns:
|
13 |
-
|
14 |
"""
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
33 |
)
|
34 |
|
35 |
-
# Launch the interface and MCP server
|
36 |
if __name__ == "__main__":
|
37 |
-
demo.launch(mcp_server=True
|
|
|
1 |
+
import numpy as np
|
2 |
import gradio as gr
|
3 |
+
from pathlib import Path
|
4 |
+
import os
|
5 |
+
from PIL import Image
|
6 |
|
7 |
+
def prime_factors(n: str):
|
8 |
"""
|
9 |
+
Compute the prime factorization of a positive integer.
|
10 |
|
11 |
Args:
|
12 |
+
n (str): The integer to factorize. Must be greater than 1.
|
13 |
+
"""
|
14 |
+
n_int = int(n)
|
15 |
+
if n_int <= 1:
|
16 |
+
raise ValueError("Input must be an integer greater than 1.")
|
17 |
+
|
18 |
+
factors = []
|
19 |
+
while n_int % 2 == 0:
|
20 |
+
factors.append(2)
|
21 |
+
n_int //= 2
|
22 |
+
|
23 |
+
divisor = 3
|
24 |
+
while divisor * divisor <= n_int:
|
25 |
+
while n_int % divisor == 0:
|
26 |
+
factors.append(divisor)
|
27 |
+
n_int //= divisor
|
28 |
+
divisor += 2
|
29 |
+
|
30 |
+
if n_int > 1:
|
31 |
+
factors.append(n_int)
|
32 |
+
|
33 |
+
return factors
|
34 |
+
|
35 |
+
def image_orientation(image: Image.Image) -> str:
|
36 |
+
"""
|
37 |
+
Returns whether image is portrait or landscape.
|
38 |
+
|
39 |
+
Args:
|
40 |
+
image (Image.Image): The image to check.
|
41 |
+
|
42 |
+
Returns:
|
43 |
+
str: "Portrait" if image is portrait, "Landscape" if image is landscape.
|
44 |
+
"""
|
45 |
+
return "Portrait" if image.height > image.width else "Landscape"
|
46 |
+
|
47 |
+
|
48 |
+
def sepia(input_img):
|
49 |
+
"""
|
50 |
+
Apply a sepia filter to the input image.
|
51 |
+
|
52 |
+
Args:
|
53 |
+
input_img (np.array): The input image to apply the sepia filter to.
|
54 |
|
55 |
Returns:
|
56 |
+
The sepia filtered image.
|
57 |
"""
|
58 |
+
sepia_filter = np.array([
|
59 |
+
[0.393, 0.769, 0.189],
|
60 |
+
[0.349, 0.686, 0.168],
|
61 |
+
[0.272, 0.534, 0.131]
|
62 |
+
])
|
63 |
+
sepia_img = input_img.dot(sepia_filter.T)
|
64 |
+
sepia_img /= sepia_img.max()
|
65 |
+
return sepia_img
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
demo = gr.TabbedInterface(
|
70 |
+
[
|
71 |
+
gr.Interface(prime_factors, gr.Textbox("1001"), gr.Textbox()),
|
72 |
+
gr.Interface(image_orientation, gr.Image(type="pil"), gr.Textbox()),
|
73 |
+
gr.Interface(sepia, gr.Image(), gr.Image()),
|
74 |
+
],
|
75 |
+
[
|
76 |
+
"Prime Factors",
|
77 |
+
"Image Orientation Checker",
|
78 |
+
"Sepia Filter",
|
79 |
+
]
|
80 |
)
|
81 |
|
|
|
82 |
if __name__ == "__main__":
|
83 |
+
demo.launch(mcp_server=True)
|