Spaces:
Runtime error
Runtime error
Timofey Fedoseev
commited on
Commit
·
f94b825
1
Parent(s):
ed25621
Add app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
3 |
+
|
4 |
+
tokenizer = T5Tokenizer.from_pretrained("jokes-tokenizer")
|
5 |
+
|
6 |
+
@st.cache
|
7 |
+
def load_model(model_name):
|
8 |
+
model = T5ForConditionalGeneration.from_pretrained("jokes-model")
|
9 |
+
return model
|
10 |
+
|
11 |
+
def infer(input_ids):
|
12 |
+
output_sequences = model.generate(input_ids=input_ids)
|
13 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
14 |
+
|
15 |
+
st.title("Stupid jokes with transformers")
|
16 |
+
st.write("Write question you want to see a funny answer for.")
|
17 |
+
sent = st.text_area("Text", height = 100)
|
18 |
+
|
19 |
+
max_source_length = 64
|
20 |
+
max_target_length = 32
|
21 |
+
prefix = "Answer the following question in a funny way: "
|
22 |
+
|
23 |
+
input_ids = tokenizer(prefix + sent, max_length=max_source_length, truncation=True, return_tensors="pt").input_ids
|
24 |
+
generated_sequence = infer(input_ids)
|
25 |
+
|
26 |
+
st.write(generated_sequence)
|