File size: 926 Bytes
134505f
 
 
 
 
62a2ac9
 
 
 
 
 
 
 
 
134505f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62a2ac9
134505f
 
 
 
 
372c8e4
134505f
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from t5 import t5
import torch
import streamlit as st
from streamlit import session_state as ses
import timeit
import random

text_list = "Prospecting Academy is a 6 weeks online course designed for business owners, marketing and sales leaders of B2B scaleup companies to help you".split()


def random_sentence():
    return " ".join(
        list(random.choice(text_list) for i in range(random.randint(4, 20)))
    )


if "page" not in ses:
    ses["page"] = "run"
    ses.out = ""
    ses.time = ""


def __run_t5():
    try:
        ses.out = t5(ses.input_text)
    except:
        ses.out = "error"


def __test_t5():
    try:
        ses.time = timeit.timeit("t5(random_sentence())", globals=globals(), number=20)
    except:
        ses.out = "error"


st.text_input("enter text", key="input_text", on_change=__run_t5)
st.write(ses.out)
if st.button("average time", on_click=__test_t5):
    st.metric("time", ses.time)