getGO007 commited on
Commit
ffcda69
Β·
verified Β·
1 Parent(s): 3e27771

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -1,9 +1,13 @@
1
  import os
2
  import streamlit as st
3
- import asyncio
4
  import nest_asyncio
5
  nest_asyncio.apply() # allow asyncio in Streamlit :contentReference[oaicite:3]{index=3}
6
 
 
 
 
 
 
7
  # ─── LlamaIndex & Parser Imports ────────────────────────────────
8
  from llama_index.core import StorageContext, load_index_from_storage
9
  from llama_index.llms.openai import OpenAI
@@ -95,7 +99,8 @@ if "workflow" not in st.session_state:
95
  # 3) User input
96
  user_input = st.text_input("Ask a question about the document:")
97
  if user_input:
98
- stop_evt: StopEvent = asyncio.run(
 
99
  st.session_state.workflow.run(
100
  index_dir=INDEX_DIR,
101
  query=user_input,
 
1
  import os
2
  import streamlit as st
 
3
  import nest_asyncio
4
  nest_asyncio.apply() # allow asyncio in Streamlit :contentReference[oaicite:3]{index=3}
5
 
6
+ import asyncio
7
+ # Create (or get) the running loop for all Workflow calls
8
+ loop = asyncio.new_event_loop()
9
+ asyncio.set_event_loop(loop)
10
+
11
  # ─── LlamaIndex & Parser Imports ────────────────────────────────
12
  from llama_index.core import StorageContext, load_index_from_storage
13
  from llama_index.llms.openai import OpenAI
 
99
  # 3) User input
100
  user_input = st.text_input("Ask a question about the document:")
101
  if user_input:
102
+ # Drive the async workflow.run() on our loop
103
+ stop_evt: StopEvent = loop.run_until_complete(
104
  st.session_state.workflow.run(
105
  index_dir=INDEX_DIR,
106
  query=user_input,