Spaces:
Sleeping
Sleeping
justheuristic
commited on
Commit
•
1051d6e
1
Parent(s):
9cbeca2
Update app.py
Browse files
app.py
CHANGED
@@ -2,17 +2,26 @@ import streamlit as st
|
|
2 |
import transformers
|
3 |
|
4 |
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
7 |
|
8 |
-
user_inputed_text = st.text_input("Insert text")
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
)
|
14 |
|
|
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
st.
|
|
|
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)
|