f1-mcp-server / app.py
arre99's picture
removed description from tabbed interface
87a229b
raw
history blame
1.85 kB
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)