|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import gradio as gr |
|
import textblob |
|
import os |
|
|
|
def func_SentimentAnalysis(str_tgtText_2_Analyze: str) -> dict: |
|
""" Analyze the sentiment of the given text. |
|
Args: |
|
str_tgtText_2_Analyze (str): The text to analyze |
|
|
|
Returns: |
|
dict_SentimentAnalysis: { polarity [-1, 1], |
|
subjectivity objective [0, 1] subjective |
|
assessment ["positive", "neutral", "negative"] |
|
} |
|
""" |
|
textBlob_tgtText = textblob.TextBlob(str_tgtText_2_Analyze) |
|
sentiment_tgtText = textBlob_tgtText.sentiment |
|
dict_SentimentAnalysis = { |
|
"polarity": round(sentiment_tgtText.polarity, 2), |
|
"subjectivity": round(sentiment_tgtText.subjectivity, 2), |
|
"assessment": "positive" if sentiment_tgtText.polarity > 0 \ |
|
else "negative" if sentiment_tgtText.polarity < 0 else "neutral" |
|
} |
|
return dict_SentimentAnalysis |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
print(f"os.getcwd() = {os.getcwd()}") |
|
os.system(f"echo ls -al {os.getcwd()} && ls -al {os.getcwd()}") |
|
os.system(f"echo ls -al /: && ls -al /") |
|
os.system(f"echo ls -al /app/: && ls -al /app/") |
|
os.system(f"echo ls -al /home/: && ls -al /home/") |
|
|
|
|
|
grInterface_SentimentAnalysis__MCP_Server = gr.Interface( |
|
fn = func_SentimentAnalysis, |
|
inputs = gr.Textbox(placeholder="Enter text to analyze..."), |
|
outputs = gr.JSON(), |
|
title = "MCP-Server: Text Sentiment Analysis", |
|
description = "Analyze the sentiment of text using TextBlob. This is an MCP-Server used by the MCP-Client https://huggingface.co/spaces/AllIllusion/MCP-Client_Qwen25-3B_Tool-SentimentAnalysis" |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
grInterface_SentimentAnalysis__MCP_Server.launch(mcp_server=True, share=True) |
|
|
|
|
|
|
|
|