Spaces:
Runtime error
Runtime error
Update app.py
Browse files79 unmodified lines8081828384858687888990919293949596979899100101102103104105106107108109110111112838485868788899091929394959697989910010110210310410510610710810911011111211311411579 unmodified lines return [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)# # 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