Skip to content

Commit

Permalink
fix: make sure hitting extract removes previous call's text output
Browse files Browse the repository at this point in the history
  • Loading branch information
William Bakst committed Apr 9, 2024
1 parent 8f764c3 commit 0325731
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions examples/streamlit/mirascope-url-extractor/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,20 @@ def generate_schema(self) -> None:

def extract():
"""Extracts a list of objects defined by the `query` from the `url`."""
begin.empty()
status = begin.status("Extracting information...")
placeholder = begin.empty()
extractor = WebpageURLExtractor(url=url, query=query)
with begin.status("Extracting information...") as status:
with status as s:
try:
st.write("Generating schema based on user query...")
extractor.generate_schema()
st.write(f"Extracting data from {url}...")
st.session_state.extracted_items = extractor.extract(retries=3)
except Exception as e:
status.error(f"Error: {e}")
status.update(state="error")
s.error(f"Error: {e}")
s.update(state="error")
return
with begin.container():
with placeholder.container():
for item in st.session_state.extracted_items:
st.write("-" * 20)
for key, value in item.model_dump().items():
Expand Down

0 comments on commit 0325731

Please sign in to comment.