File size: 1,853 Bytes
014f597
1d0b9d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
014f597
 
1d0b9d1
 
 
 
87a229b
1d0b9d1
014f597
1d0b9d1
014f597
1d0b9d1
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
import gradio as gr

def sentiment_analysis(text: str) -> dict:
    """
    Analyze the sentiment of the given text.

    Args:
        text (str): The text to analyze

    Returns:
        dict: A dictionary containing polarity, subjectivity, and assessment
    """
    blob = TextBlob(text)
    sentiment = blob.sentiment
    
    return {
        "polarity": round(sentiment.polarity, 2),  # -1 (negative) to 1 (positive)
        "subjectivity": round(sentiment.subjectivity, 2),  # 0 (objective) to 1 (subjective)
        "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
    }

def driver_championship_score(driver_name: str) -> str:
    """
    Get the championship score for the given driver.

    Args:
        driver_name (str): The driver's name

    Returns:
        int: The driver's championship score
    """
    return f"Driver {driver_name} has {random.randint(0, 100)} championship points"


def driver_position(driver_name: str) -> str:
    """
    Get the current position of the given driver.

    Args:
        driver_name (str): The driver's name

    Returns:
        str: The driver's current position
    """
    return f"Driver {driver_name} is in position {random.randint(1, 20)}"



# Create interfaces for each tool
iface1 = gr.Interface(
    fn=driver_championship_score,
    inputs="text",
    outputs="text",
    title="Driver Championship Score"
)

iface2 = gr.Interface(
    fn=driver_position,
    inputs="text",
    outputs="text",
    title="Driver Position"
)

# Combine into tabs into server
gradio_server = gr.TabbedInterface(
    [iface1, iface2],
    tab_names=["Driver Championship Score", "Driver Position"],
    title="Formula 1 MCP server"
)

# Launch the interface and MCP server
if __name__ == "__main__":
    gradio_server.launch(mcp_server=True)