justheuristic commited on
Commit
1051d6e
1 Parent(s): 9cbeca2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -2,17 +2,26 @@ import streamlit as st
2
  import transformers
3
 
4
 
5
- model = transformers.AutoModelForCausalLM.from_pretrained("distilgpt2")
6
- tokenizer = transformers.AutoTokenizer.from_pretrained("distilgpt2")
 
 
 
7
 
8
- user_inputed_text = st.text_input("Insert text")
9
 
10
- outputs = model.generate(
11
- **tokenizer([user_inputed_text], return_tensors='pt'),
12
- max_new_tokens=50, do_sample=True,
13
- )
14
 
 
15
 
16
- outputs_text = tokenizer.decode(outputs[0])
 
 
 
 
 
 
 
17
 
18
- st.text_area(label='output', value="your text is :" + user_inputed_text[::-1])
 
2
  import transformers
3
 
4
 
5
+ @st.cache
6
+ def load_stuff():
7
+ model = transformers.AutoModelForCausalLM.from_pretrained("distilgpt2")
8
+ tokenizer = transformers.AutoTokenizer.from_pretrained("distilgpt2")
9
+ return model, tokenizer
10
 
 
11
 
12
+ st.image("./img.jpg")
13
+
14
+ model, tokenizer = load_stuff()
 
15
 
16
+ user_inputed_text = st.text_input("Insert text")
17
 
18
+ if len(user_inputed_text) == 0:
19
+ outputs_text = "no text provided. write some text, meatbag"
20
+ else:
21
+ outputs = model.generate(
22
+ **tokenizer([user_inputed_text], return_tensors='pt'),
23
+ max_new_tokens=50, do_sample=True,
24
+ )
25
+ outputs_text = tokenizer.decode(outputs[0])
26
 
27
+ st.write(value=outputs_text)