Spaces:
Build error
Build error
stream streamlit stdout
Browse files
app.py
CHANGED
|
@@ -4,8 +4,35 @@ import numpy as np
|
|
| 4 |
|
| 5 |
from src.Surveyor import Surveyor
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def run_survey(surveyor, research_keywords, max_search, num_papers):
|
| 8 |
-
|
|
|
|
| 9 |
max_search=max_search,
|
| 10 |
num_papers=num_papers
|
| 11 |
)
|
|
@@ -28,15 +55,13 @@ def run_survey(surveyor, research_keywords, max_search, num_papers):
|
|
| 28 |
|
| 29 |
|
| 30 |
def survey_space(surveyor):
|
| 31 |
-
|
| 32 |
-
st.title('Automated Survey generation from research keywords - Auto-Research V0.1')
|
| 33 |
-
|
| 34 |
form = st.sidebar.form(key='survey_form')
|
| 35 |
research_keywords = form.text_input("What would you like to research in today?")
|
| 36 |
max_search = form.number_input("num_papers_to_search", help="maximium number of papers to glance through - defaults to 20",
|
| 37 |
-
min_value=1, max_value=60, value=
|
| 38 |
num_papers = form.number_input("num_papers_to_select", help="maximium number of papers to select and analyse - defaults to 8",
|
| 39 |
-
min_value=1, max_value=25, value=
|
| 40 |
submit = form.form_submit_button('Submit')
|
| 41 |
|
| 42 |
if submit:
|
|
|
|
| 4 |
|
| 5 |
from src.Surveyor import Surveyor
|
| 6 |
|
| 7 |
+
import contextlib
|
| 8 |
+
from functools import wraps
|
| 9 |
+
from io import StringIO
|
| 10 |
+
|
| 11 |
+
def capture_output(func):
|
| 12 |
+
"""Capture output from running a function and write using streamlit."""
|
| 13 |
+
|
| 14 |
+
@wraps(func)
|
| 15 |
+
def wrapper(*args, **kwargs):
|
| 16 |
+
# Redirect output to string buffers
|
| 17 |
+
stdout, stderr = StringIO(), StringIO()
|
| 18 |
+
try:
|
| 19 |
+
with contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(stderr):
|
| 20 |
+
return func(*args, **kwargs)
|
| 21 |
+
except Exception as err:
|
| 22 |
+
st.write(f"Failure while executing: {err}")
|
| 23 |
+
finally:
|
| 24 |
+
if _stdout := stdout.getvalue():
|
| 25 |
+
st.write("Execution stdout:")
|
| 26 |
+
st.code(_stdout)
|
| 27 |
+
if _stderr := stderr.getvalue():
|
| 28 |
+
st.write("Execution stderr:")
|
| 29 |
+
st.code(_stderr)
|
| 30 |
+
|
| 31 |
+
return wrapper
|
| 32 |
+
|
| 33 |
def run_survey(surveyor, research_keywords, max_search, num_papers):
|
| 34 |
+
survey_fn = capture_output(surveyor.survey)
|
| 35 |
+
zip_file_name, survey_file_name = survey_fn(research_keywords,
|
| 36 |
max_search=max_search,
|
| 37 |
num_papers=num_papers
|
| 38 |
)
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
def survey_space(surveyor):
|
| 58 |
+
st.sidebar.title('Auto-Research V0.1 - Automated Survey generation from research keywords')
|
|
|
|
|
|
|
| 59 |
form = st.sidebar.form(key='survey_form')
|
| 60 |
research_keywords = form.text_input("What would you like to research in today?")
|
| 61 |
max_search = form.number_input("num_papers_to_search", help="maximium number of papers to glance through - defaults to 20",
|
| 62 |
+
min_value=1, max_value=60, value=10, step=1, key='max_search')
|
| 63 |
num_papers = form.number_input("num_papers_to_select", help="maximium number of papers to select and analyse - defaults to 8",
|
| 64 |
+
min_value=1, max_value=25, value=2, step=1, key='num_papers')
|
| 65 |
submit = form.form_submit_button('Submit')
|
| 66 |
|
| 67 |
if submit:
|