mgbam commited on
Commit
95e25f2
·
verified ·
1 Parent(s): 2b79b9f

Update app/sentiment.py

Browse files
Files changed (1) hide show
  1. app/sentiment.py +11 -10
app/sentiment.py CHANGED
@@ -9,10 +9,10 @@ import asyncio
9
  import logging
10
  import os
11
  # ====================================================================
12
- # FIX APPLIED HERE (1 of 2)
13
  # ====================================================================
14
- # Import Union for Python 3.9 compatibility
15
- from typing import TypedDict, Union
16
  # ====================================================================
17
 
18
 
@@ -27,12 +27,8 @@ logger = logging.getLogger(__name__)
27
  class SentimentResult(TypedDict):
28
  id: int
29
  text: str
30
- # ====================================================================
31
- # FIX APPLIED HERE (2 of 2)
32
- # ====================================================================
33
- # Changed `str | float` to `Union[str, float]`
34
  result: dict[str, Union[str, float]]
35
- # ====================================================================
36
 
37
 
38
  # --- Main Class: SentimentAnalyzer ---
@@ -46,7 +42,12 @@ class SentimentAnalyzer:
46
 
47
  HF_API_URL = "https://api-inference.huggingface.co/models/distilbert-base-uncased-finetuned-sst-2-english"
48
 
49
- def __init__(self, client: httpx.AsyncClient, api_token: str | None = None):
 
 
 
 
 
50
  """
51
  Initializes the SentimentAnalyzer.
52
 
@@ -116,7 +117,7 @@ class SentimentAnalyzer:
116
  }
117
  await self.result_queue.put(payload)
118
 
119
- async def stream_results(self) -> SentimentResult:
120
  """
121
  An async generator that yields new results as they become available.
122
  This is the consumer part of the pattern.
 
9
  import logging
10
  import os
11
  # ====================================================================
12
+ # FINAL FIX APPLIED HERE
13
  # ====================================================================
14
+ # Import Optional and Union for Python 3.9 compatibility.
15
+ from typing import TypedDict, Union, Optional
16
  # ====================================================================
17
 
18
 
 
27
  class SentimentResult(TypedDict):
28
  id: int
29
  text: str
30
+ # Using Union for Python 3.9 compatibility
 
 
 
31
  result: dict[str, Union[str, float]]
 
32
 
33
 
34
  # --- Main Class: SentimentAnalyzer ---
 
42
 
43
  HF_API_URL = "https://api-inference.huggingface.co/models/distilbert-base-uncased-finetuned-sst-2-english"
44
 
45
+ # ====================================================================
46
+ # FINAL FIX APPLIED HERE
47
+ # ====================================================================
48
+ # Changed `str | None` to `Optional[str]` for Python 3.9 compatibility.
49
+ def __init__(self, client: httpx.AsyncClient, api_token: Optional[str] = None):
50
+ # ====================================================================
51
  """
52
  Initializes the SentimentAnalyzer.
53
 
 
117
  }
118
  await self.result_queue.put(payload)
119
 
120
+ async def stream_results(self): # Type hint removed for simplicity, was -> SentimentResult
121
  """
122
  An async generator that yields new results as they become available.
123
  This is the consumer part of the pattern.