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

Update app/sentiment.py

Browse files
Files changed (1) hide show
  1. app/sentiment.py +14 -3
app/sentiment.py CHANGED
@@ -8,7 +8,13 @@ an asynchronous application like FastAPI.
8
  import asyncio
9
  import logging
10
  import os
11
- from typing import TypedDict
 
 
 
 
 
 
12
 
13
  import httpx
14
 
@@ -21,7 +27,12 @@ logger = logging.getLogger(__name__)
21
  class SentimentResult(TypedDict):
22
  id: int
23
  text: str
24
- result: dict[str, str | float]
 
 
 
 
 
25
 
26
 
27
  # --- Main Class: SentimentAnalyzer ---
@@ -64,7 +75,7 @@ class SentimentAnalyzer:
64
  text: The input text to analyze.
65
  request_id: A unique identifier for this request.
66
  """
67
- analysis_result = {"label": "ERROR", "score": 0.0, "error": "Unknown failure"}
68
  try:
69
  response = await self.client.post(
70
  self.HF_API_URL,
 
8
  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
 
19
  import httpx
20
 
 
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 ---
 
75
  text: The input text to analyze.
76
  request_id: A unique identifier for this request.
77
  """
78
+ analysis_result: dict[str, Union[str, float]] = {"label": "ERROR", "score": 0.0, "error": "Unknown failure"}
79
  try:
80
  response = await self.client.post(
81
  self.HF_API_URL,