Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -142,8 +142,19 @@ async def sentiment_stream(request: Request):
|
|
142 |
</p>
|
143 |
</div>
|
144 |
"""
|
145 |
-
#
|
146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
except (KeyError, TypeError):
|
148 |
continue # Ignore malformed payloads
|
149 |
|
@@ -152,5 +163,5 @@ async def sentiment_stream(request: Request):
|
|
152 |
# --- Main execution block for local development ---
|
153 |
if __name__ == "__main__":
|
154 |
import uvicorn
|
155 |
-
# Correct run command for a file named 'app.py'
|
156 |
uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)
|
|
|
142 |
</p>
|
143 |
</div>
|
144 |
"""
|
145 |
+
# ====================================================================
|
146 |
+
# FIX APPLIED HERE
|
147 |
+
# ====================================================================
|
148 |
+
# 1. First, process the string to remove newlines. This avoids a
|
149 |
+
# backslash in the f-string expression, fixing the SyntaxError.
|
150 |
+
data_payload = html_fragment.replace('\n', '')
|
151 |
+
|
152 |
+
# 2. Then, use the clean variable in the f-string to build the message.
|
153 |
+
sse_message = f"event: sentiment_update\ndata: {data_payload}\n\n"
|
154 |
+
|
155 |
+
yield sse_message
|
156 |
+
# ====================================================================
|
157 |
+
|
158 |
except (KeyError, TypeError):
|
159 |
continue # Ignore malformed payloads
|
160 |
|
|
|
163 |
# --- Main execution block for local development ---
|
164 |
if __name__ == "__main__":
|
165 |
import uvicorn
|
166 |
+
# Correct run command for a file named 'app.py' in the root directory.
|
167 |
uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)
|