Skip to content

Commit 89bbf46

Browse files
added code for streamlit deployment2
1 parent 465e91f commit 89bbf46

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

FASTAPI-DEPLOYMENT/streamlit_standalone.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,26 @@ async def process_message_standard(user_id: str, message: str):
196196
request_start = time.time()
197197
timing_placeholder.info("⏳ Processing request...")
198198

199-
# Run async pipeline
200-
loop = asyncio.new_event_loop()
201-
asyncio.set_event_loop(loop)
199+
# Run async pipeline - handle event loop properly for Streamlit
200+
try:
201+
# Try to get existing event loop
202+
loop = asyncio.get_event_loop()
203+
if loop.is_closed():
204+
loop = asyncio.new_event_loop()
205+
asyncio.set_event_loop(loop)
206+
except RuntimeError:
207+
# No event loop exists, create new one
208+
loop = asyncio.new_event_loop()
209+
asyncio.set_event_loop(loop)
202210

203211
try:
204212
if stream_mode == "Streaming":
205213
# For streaming, we'll use the standard pipeline but display progressively
206214
# Note: True streaming requires the streaming endpoint, but for standalone
207215
# we'll simulate it with progressive display
208-
result = await process_message_streaming(user_id, prompt)
216+
result = loop.run_until_complete(process_message_streaming(user_id, prompt))
209217
else:
210-
result = await process_message_standard(user_id, prompt)
218+
result = loop.run_until_complete(process_message_standard(user_id, prompt))
211219

212220
total_time = time.time() - request_start
213221
full_response = result.get('answer', '')
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)