File size: 2,748 Bytes
af9d55b
da2de7a
af9d55b
 
 
da2de7a
af9d55b
da2de7a
af9d55b
da2de7a
 
af9d55b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da2de7a
 
af9d55b
da2de7a
af9d55b
 
 
 
 
 
 
 
 
e391d62
 
af9d55b
e391d62
 
 
812e2f4
 
 
 
 
 
 
 
 
 
e391d62
 
 
 
af9d55b
0db572d
af9d55b
 
0db572d
e391d62
af9d55b
 
 
812e2f4
 
af9d55b
 
0db572d
e391d62
af9d55b
 
 
812e2f4
 
af9d55b
da2de7a
 
 
af9d55b
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
104
105
106
107
108
109
110
111
112
import numpy as np
import gradio as gr
from pathlib import Path
import os
from PIL import Image

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

    Args:
        n (str): The integer to factorize. Must be greater than 1.
    """
    n_int = int(n)
    if n_int <= 1:
        raise ValueError("Input must be an integer greater than 1.")

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

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

    if n_int > 1:
        factors.append(n_int)

    return factors

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 (np.array): 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

def echo(message, history):
    return message

def vote(data: gr.LikeData):
    print(data.liked)


def add(a: int, b: int) -> int:
    """Add two numbers"""
    return a + b

def multiply(a: int, b: int) -> int:
    """Multiply two numbers"""
    return a * b


with gr.Blocks() as chat_ui:
    chatbot = gr.Chatbot(placeholder="<strong>Your Personal Echo-Man</strong><br>Ask Me Anything")
    chatbot.like(vote, None, None)
    gr.ChatInterface(fn=echo, type="messages", chatbot=chatbot, examples=["hello", "hola", "merhaba"], title="Echo Bot")

from app_tool import demo as ui
demo = gr.TabbedInterface(
    [
        ui,
        chat_ui,
        gr.Interface(prime_factors, gr.Textbox("1001"), gr.Textbox()),
        gr.Interface(image_orientation, gr.Image(type="pil"), gr.Textbox()),
        gr.Interface(sepia, gr.Image(), gr.Image()),
        gr.Interface(add, [gr.Number(), gr.Number()], gr.Number()),
        gr.Interface(multiply, [gr.Number(), gr.Number()], gr.Number())
    ],
    [
        "Langgraph Chatbot",
        "Chat UI",
        "Prime Factors",
        "Image Orientation Checker",
        "Sepia Filter",
        "Add",
        "multiply"
    ]
)

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