Spaces:
Runtime error
Runtime error
Update app.py
Browse files79 unmodified lines808182838485868788899091929394959697989910010110210310410510610710810911011111211311411579 unmodified linesreturn [f"Network error: {e}"]# Tool 2: Sentiment Analysisdef sentiment_analysis(text: str) -> str:"""Analyzes the sentiment of a given text using TextBlob.Args:text (str): The text to analyze. Must not be empty.Returns:A JSON string with:- polarity: -1 (negative) to 1 (positive)- subjectivity: 0 (objective) to 1 (subjective)- assessment: 'positive', 'negative', or 'neutral'"""if not text:return json.dumps({"error": "Input text cannot be empty."})blob = TextBlob(text)polarity = round(blob.sentiment.polarity, 2)subjectivity = round(blob.sentiment.subjectivity, 2)if polarity > 0.1:assessment = "positive"elif polarity < -0.1:assessment = "negative"else:assessment = "neutral"return json.dumps({"polarity": polarity,"subjectivity": subjectivity,"assessment": assessment}, indent=2)# --- Gradio Interface Setup ---79 unmodified lines808182838485868788899091929394959697989910010110210310410510610710810911011111211311411579 unmodified linesreturn [f"Network error: {e}"]# # Tool 2: Sentiment Analysis# def sentiment_analysis(text: str) -> str:# """# Analyzes the sentiment of a given text using TextBlob.# Args:# text (str): The text to analyze. Must not be empty.# Returns:# A JSON string with:# - polarity: -1 (negative) to 1 (positive)# - subjectivity: 0 (objective) to 1 (subjective)# - assessment: 'positive', 'negative', or 'neutral'# """# if not text:# return json.dumps({"error": "Input text cannot be empty."})# blob = TextBlob(text)# polarity = round(blob.sentiment.polarity, 2)# subjectivity = round(blob.sentiment.subjectivity, 2)# if polarity > 0.1:# assessment = "positive"# elif polarity < -0.1:# assessment = "negative"# else:# assessment = "neutral"# return json.dumps({# "polarity": polarity,# "subjectivity": subjectivity,# "assessment": assessment# }, indent=2)# --- Gradio Interface Setup ---
app.py+30-30