File size: 1,025 Bytes
f8987ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
import streamlit as st
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline

st.title('Sinhala Text generation with GPT2')
st.markdown('A simple demo using Sinhala-gpt2 model trained during hf-flax week')

seed = st.text_input('Starting text', 'ආයුබෝවන්')
seq_num = st.number_input('Number of sentences to generate ', 1, 20, 5)
max_len = st.number_input('Length of the sentence ', 5, 300, 100)

go = st.button('Generate')

st.write('Waiting for the model to load.....')
model = AutoModelForCausalLM.from_pretrained('flax-community/Sinhala-gpt2')
tokenizer = AutoTokenizer.from_pretrained('flax-community/Sinhala-gpt2')
st.write('Model loaded!!')

if go:
    try:
        generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
        seqs = generator(seed, max_length=max_len, num_return_sequences=seq_num)
        st.write(seqs)
    except Exception as e:
        st.exception(f'Exception: {e}')

st.markdown('____________')
st.markdown('by Keshan with Flax Community')