File size: 1,892 Bytes
4241560
 
 
 
 
f164167
4241560
7346e8c
4241560
 
9ad6c08
4241560
 
 
 
 
 
eb5f7d6
4241560
30ab26a
4241560
 
 
 
 
948a506
4241560
 
 
46005e9
4241560
 
 
 
e230cfc
4241560
f512a02
eb5f7d6
f512a02
eb5f7d6
e230cfc
 
4241560
 
 
 
 
 
8ed5f27
8f68673
4241560
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import streamlit as st
import time
from transformers import pipeline
import torch
trust_remote_code=True
st.markdown('## Text-generation gpt-ya from Breadlicker45')
use_auth_token=True
tokenizer.padding_side = "left"
@st.cache(allow_output_mutation=True, suppress_st_warning =True, show_spinner=False)
def get_model():
    return pipeline('text-generation', model=model, do_sample=False)
    
col1, col2 = st.columns([2,1])

with st.sidebar:
    st.markdown('## Model Parameters')

    max_length = st.slider('Max text length', 0, 500, 80)

    num_beams = st.slider('N° tree beams search', 1, 15,  2)

    early_stopping = st.selectbox(
     'Early stopping text generation',
     ('True', 'False'), key={'True' : True, 'False': False}, index=0)

    no_ngram_repeat = st.slider('Max repetition limit', 1, 5,  2)
    
with col1:
    prompt= st.text_area('Your prompt here',
        '''What is the meaning of life?''') 
        
with col2:
    select_model = st.radio(
        "Select the model to use:",
        ('gpt-ya', 'gpt-ya-1-1', 'gpt-ya-1-1-160M'), index = 2)

    if select_model == 'gpt-ya':
        model = 'breadlicker45/gpt-ya'
    elif select_model == 'gpt-ya-1-1':
        model = 'BreadAi/gpt-YA-1-1_70M'
    elif select_model == 'gpt-ya-1-1-160M':
        model = 'BreadAi/gpt-YA-1-1_160M'

    with st.spinner('Loading Model... (This may take a while)'):
        generator = get_model()    
        st.success('Model loaded correctly!')
     
gen = st.info('Generating text...')
answer = generator(prompt, max_length=max_length, no_repeat_ngram_size=no_ngram_repeat, 
                   early_stopping=early_stopping, num_beams=num_beams, do_sample=False)                      
gen.empty()                      
                       
lst = answer[0]['generated_text']
   
t = st.empty()
for i in range(len(lst)):
    t.markdown("#### %s" % lst[0:i])
    time.sleep(0.04)