######################################################################### # Copyright (C) # # 2025-June Sen Li (Sen.Li.Sprout@gmail.com) # # Permission given to modify the code only for Non-Profit Research # # as long as you keep this declaration at the top # ######################################################################### 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 # Launch the interface and MCP server 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/") # Create the Gradio interface, as the MCP-Server 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" ) # MCP Schema: Visit http://localhost:7860/gradio_api/mcp/schema # MCP Server: # Setting mcp_server=True enables the MCP server, enable using the environment variable: # export GRADIO_MCP_SERVER=True # http://localhost:7860/gradio_api/mcp/sse # https://allillusion-mcp-server-sentimentanalysis.hf.space/gradio_api/mcp/sse grInterface_SentimentAnalysis__MCP_Server.launch(mcp_server=True, share=True) # os.system(f"echo ls -al /app/flagged/: && ls -al /app/flagged/") # os.system(f"echo ls -al /.gradio/flagged/: && ls -al /.gradio/flagged/")