Techno-1 commited on
Commit
d8f59b2
·
verified ·
1 Parent(s): 0a6e9c3

Added logging

Browse files

Trying to figure out why I don't get any network responses even though requests are accepted

Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -1,24 +1,31 @@
1
  import gradio as gr
2
  from textblob import TextBlob
 
 
 
 
 
3
 
4
  def sentiment_analysis(text: str) -> dict:
5
  """
6
  Analyze the sentiment of the given text.
7
-
8
  Args:
9
  text (str): The text to analyze
10
-
11
  Returns:
12
  dict: A dictionary containing polarity, subjectivity, and assessment
13
  """
 
14
  blob = TextBlob(text)
15
  sentiment = blob.sentiment
16
 
17
- return {
18
- "polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
19
- "subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
20
  "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
21
  }
 
 
 
22
 
23
  # Create the Gradio interface
24
  demo = gr.Interface(
@@ -31,4 +38,5 @@ demo = gr.Interface(
31
 
32
  # Launch the interface and MCP server
33
  if __name__ == "__main__":
 
34
  demo.launch(mcp_server=True)
 
1
  import gradio as gr
2
  from textblob import TextBlob
3
+ import logging
4
+
5
+ # Set up basic logging
6
+ logging.basicConfig(level=logging.INFO)
7
+ logger = logging.getLogger(__name__)
8
 
9
  def sentiment_analysis(text: str) -> dict:
10
  """
11
  Analyze the sentiment of the given text.
 
12
  Args:
13
  text (str): The text to analyze
 
14
  Returns:
15
  dict: A dictionary containing polarity, subjectivity, and assessment
16
  """
17
+ logger.info(f"Received input: {text}")
18
  blob = TextBlob(text)
19
  sentiment = blob.sentiment
20
 
21
+ result = {
22
+ "polarity": round(sentiment.polarity, 2),
23
+ "subjectivity": round(sentiment.subjectivity, 2),
24
  "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
25
  }
26
+
27
+ logger.info(f"Returning result: {result}")
28
+ return result
29
 
30
  # Create the Gradio interface
31
  demo = gr.Interface(
 
38
 
39
  # Launch the interface and MCP server
40
  if __name__ == "__main__":
41
+ logger.info("Starting Gradio app...")
42
  demo.launch(mcp_server=True)