Patinya commited on
Commit
b5d77b6
1 Parent(s): e5cc3fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -1,22 +1,19 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
 
 
4
  classifier = pipeline("translation", model="t5-base")
5
  def main():
6
- st.title("Text generation")
7
 
8
  with st.form("text_field"):
9
- question = "What is 42?"
10
- context = "42 is the answer to life, the universe and everything"
11
- input = f"question: {question} context: {context}"
12
- encoded_input = tokenizer([input],
13
- return_tensors='pt',
14
- max_length=512,
15
- truncation=True)
16
- output = model.generate(input_ids = encoded_input.input_ids,
17
- attention_mask = encoded_input.attention_mask)
18
- output = tokenizer.decode(output[0], skip_special_tokens=True)
19
- print(output)
20
-
21
  if __name__ == "__main__":
22
  main()
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ #model = AutoModelForSeq2SeqLM.from_pretrained("t5-base")
5
+ #tokenizer = AutoTokenizer.from_pretrained("t5-base")
6
  classifier = pipeline("translation", model="t5-base")
7
  def main():
8
+ st.title("Text translation")
9
 
10
  with st.form("text_field"):
11
+ text = st.text_area('enter some text:')
12
+ # clicked==True only when the button is clicked
13
+ clicked = st.form_submit_button("Submit")
14
+ if clicked:
15
+ results = classifier([text])
16
+ st.json(results)
17
+
 
 
 
 
 
18
  if __name__ == "__main__":
19
  main()