|
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), |
|
"subjectivity": round(sentiment.subjectivity, 2), |
|
"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)}" |
|
|
|
|
|
|
|
|
|
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" |
|
) |
|
|
|
|
|
gradio_server = gr.TabbedInterface( |
|
[iface1, iface2], |
|
tab_names=["Driver Championship Score", "Driver Position"], |
|
title="Formula 1 MCP server" |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
gradio_server.launch(mcp_server=True) |