Spaces:
abidlabs
/
Running on CPU Upgrade

File size: 2,391 Bytes
5910b93
ea9225f
5910b93
 
 
ea9225f
5910b93
ea9225f
5910b93
ea9225f
 
5910b93
ea9225f
 
5910b93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea9225f
 
 
5910b93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import numpy as np
import gradio as gr
from pathlib import Path
import os
from PIL import Image

def prime_factors(n):
    """
    Compute the prime factorization of a positive integer.

    Args:
        n (int): The integer to factorize. Must be greater than 1.

    Returns:
        List[int]: A list of prime factors in ascending order.

    Raises:
        ValueError: If n is not greater than 1.
    """
    n = int(n)
    if n <= 1:
        raise ValueError("Input must be an integer greater than 1.")

    factors = []
    while n % 2 == 0:
        factors.append(2)
        n //= 2

    divisor = 3
    while divisor * divisor <= n:
        while n % divisor == 0:
            factors.append(divisor)
            n //= divisor
        divisor += 2

    if n > 1:
        factors.append(n)

    return factors


def generate_cheetah_image():
    """
    Generate a cheetah image.

    Returns:
        The generated cheetah image.
    """
    return Path(os.path.dirname(__file__)) / "cheetah.jpg"


def image_orientation(image: Image.Image) -> str:
    """
    Returns whether image is portrait or landscape.

    Args:
        image (Image.Image): The image to check.

    Returns:
        str: "Portrait" if image is portrait, "Landscape" if image is landscape.
    """
    return "Portrait" if image.height > image.width else "Landscape"


def sepia(input_img):
    """
    Apply a sepia filter to the input image.

    Args:
        input_img (str): The input image to apply the sepia filter to.

    Returns:
        The sepia filtered image.
    """
    sepia_filter = np.array([
        [0.393, 0.769, 0.189],
        [0.349, 0.686, 0.168],
        [0.272, 0.534, 0.131]
    ])
    sepia_img = input_img.dot(sepia_filter.T)
    sepia_img /= sepia_img.max()
    return sepia_img



demo = gr.TabbedInterface(
    [
        gr.Interface(prime_factors, gr.Textbox(), gr.Textbox(), api_name="prime_factors"),
        gr.Interface(generate_cheetah_image, None, gr.Image(), api_name="generate_cheetah_image"),
        gr.Interface(image_orientation, gr.Image(type="pil"), gr.Textbox(), api_name="image_orientation"),
        gr.Interface(sepia, gr.Image(), gr.Image(), api_name="sepia"),
    ],
    [
        "Prime Factors",
        "Cheetah Image",
        "Image Orientation Checker",
        "Sepia Filter",
    ]
)

if __name__ == "__main__":
    demo.launch(mcp_server=True)