File size: 981 Bytes
45680a7
 
 
 
 
 
 
da92290
 
 
0fbbee1
 
da92290
0fbbee1
 
 
 
 
 
 
 
70bf880
0fbbee1
 
 
 
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
import os
os.system("pip install transformers") 
os.system("pip install sentencepiece") 
os.system("pip install torch torchvision") 



import streamlit as st
from transformers import T5Tokenizer, T5ForConditionalGeneration

tokenizer = T5Tokenizer.from_pretrained("t5-base")
model = T5ForConditionalGeneration.from_pretrained("t5-base")

st.title('T5 Text Generation App')
st.write('Enter the text you want to generate:')
input_text = st.text_input('Input Text', 'Once upon a time,')

if st.button('Generate Text'):
    input_text = input_text.strip()
    input_text = "generate text:{}".format(input_text)  # Add the generation prefix
    input_ids = tokenizer.encode(input_text, return_tensors='pt', max_length=512, truncation=True)
    outputs = model.generate(input_ids, max_length=512) # Specify the maximum length of the generated text
    generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
    st.write('Generated Text:')
    st.write(generated_text)