예제 #1
0
def run_labeler():

    state = SessionState.get(vnum=0, vlab=0)
    vlist = get_video_list()

    st.title("Emotion Labeler")
    st.write(
        "Please label as many videos as you can. When done, simply close browser tab."
    )
    st.write("")
    st.write(f"Total videos labeled in current session:{state.vlab}")
    st.write("Note: refreshing browser tab will reset counts.")

    vrnd, choices = get_random_video(vlist, state.vnum)
    vpath = f'{bucket_path}vid_{vrnd}.mp4'
    with open(vpath, 'rb') as video_file:
        vbytes = video_file.read()
    st.video(vbytes)

    labeled = False
    emo = st.selectbox('Emotion:', choices)
    if emo[:6] != "Select":
        labeled = True

    if st.button('Get next video'):
        if labeled:
            state.vlab += 1
            with open(labelfile, 'a') as fd:
                fd.write(
                    f"{time.time()}, {SessionState.get_session_id()}, {vrnd}, {emo}\n"
                )
        state.vnum += 1
        raise RerunException(RerunData(widget_state=None))
예제 #2
0
def main():

    df = read_jarchive()
    state = SessionState.get(question_number=1, num_correct=0, score=0)

    st.title("Streamlit Jeopardy!")

    category, question, answer, value = get_one_question(
        state.question_number, df)
    answered = False

    st.write(f"Question from category {category} for ${value}:")
    st.write(f"    {question}")
    response = st.text_input("What is: ", key=str(state.question_number))

    if (response != ''):
        sresponse = sanitize(response)
        sanswer = sanitize(answer)

        if (compare_strings(sresponse, sanswer) >= 0.5):
            answered = True
            st.write(f"Correct! The reference answer is {answer}.")
        else:
            answered = False
            st.write(
                f"Sorry! Your response was {response}. The correct answer is {answer}."
            )

        if (answered):
            state.num_correct += 1
            state.score += value
        else:
            state.score -= value
        st.write(
            f"Your score is {state.num_correct}/{state.question_number} and winnings are ${state.score}"
        )
        st.write("")

    if st.button('Next question'):
        state.question_number += 1
        raise RerunException(RerunData(widget_state=None))

    if st.button('Reset score'):
        state.question_number = 0
        state.num_correct = 0
        state.score = 0
        raise RerunException(RerunData(widget_state=None))
def reset_session(session):
    session.message_value = None
    raise RerunException(RerunData(widget_state=None))
예제 #4
0
def rerun():
    """Rerun a Streamlit app from the top!"""
    widget_states = _get_widget_states()
    raise RerunException(RerunData(widget_states))
예제 #5
0
    ans = arr[0] * arr[1]
    choices = ["Please select an answer", ans, ans - 1, ans + 1, ans + 2]
    return arr, q, ans, choices


arr, q, ans, choices = get_question(state.question_number)
answered = False
st.write(f"Your score is {state.num_correct}/{state.question_number}")
st.write("")
st.text(f"Solve: {q}")
a = st.selectbox('Answer:', choices)

if a != "Please select an answer":
    st.write(f"You chose {a}")
    if (ans == a):
        answered = True
        st.write(f"Correct!")
    else:
        st.write(f"Wrong!, the correct answer is {ans}")

if st.button('Next question'):
    state.question_number += 1
    if (answered):
        state.num_correct += 1
    raise RerunException(RerunData(widget_state=None))

if st.button('Reset'):
    state.question_number = 0
    state.num_correct = 0
    raise RerunException(RerunData(widget_state=None))
예제 #6
0
def rerun():
    """Rerun a Streamlit app from the top!
    refer to https://gist.github.com/tvst/58c42300d3b6de48e805af7429cac2e7
    """
    widget_states = _get_widget_states()
    raise RerunException(RerunData(widget_states))
예제 #7
0
top_row = pd.DataFrame({
    'Country': ['Select a Country'],
    'Slug': ['Empty'],
    'ISO2': ['E']
})
# Concat with old DataFrame and reset the Index.
df0 = pd.concat([top_row, df0]).reset_index(drop=True)

st.sidebar.header('Filter your search')
graph_type = st.sidebar.selectbox('Cases type',
                                  ('confirmed', 'deaths', 'recovered'))
st.sidebar.subheader('Search by country 📌')
country = st.sidebar.selectbox('Country', df0.Country)
country1 = st.sidebar.selectbox('Compare with another Country', df0.Country)
if st.sidebar.button('Refresh Data'):
    raise RerunException(st.ScriptRequestQueue.RerunData(None))

if country != 'Select a Country':
    slug = df0.Slug[df0['Country'] == country].to_string(index=False)[1:]
    url = 'https://api.covid19api.com/total/dayone/country/' + slug + '/status/' + graph_type
    r = requests.get(url)
    st.write("""# Total """ + graph_type + """ cases in """ + country +
             """ are: """ + str(r.json()[-1].get("Cases")))
    df = pd.json_normalize(r.json())
    layout = go.Layout(
        title=country + '\'s ' + graph_type + ' cases Data',
        xaxis=dict(title='Date'),
        yaxis=dict(title='Number of cases'),
    )
    fig.update_layout(dict1=layout, overwrite=True)
    fig.add_trace(go.Scatter(x=df.Date, y=df.Cases, mode='lines',
예제 #8
0
def rerun():
    """Rerun a Streamlit app from the top!"""
    widget_states = st_session()._widget_states
    raise RerunException(RerunData(widget_states))