File size: 1,922 Bytes
0f85201
bb55c9f
b7851ed
0f85201
b7851ed
 
 
 
383ea2b
 
b7851ed
383ea2b
2b2e35b
b7851ed
 
 
 
 
 
64fd31c
 
 
 
383ea2b
 
 
 
 
 
 
 
 
 
 
64fd31c
383ea2b
2c8db61
bb55c9f
b7851ed
 
2b2e35b
344bac3
b7851ed
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import AutoTokenizer, AutoModelWithLMHead, GPT2Tokenizer, GPT2Model, FlaxGPT2LMHeadModel, GPT2LMHeadModel, pipeline, set_seed
import torch

#===========================================#
#        Loads Model and Pipeline        #
#===========================================#

# tokenizer = AutoTokenizer.from_pretrained("flax-community/swe-gpt-wiki")
# model = AutoModelWithLMHead.from_pretrained("flax-community/swe-gpt-wiki")

# generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
# set_seed(42)


#===========================================#
#              Streamlit Code               #
#===========================================#

# result = st.sidebar.selectbox(
#     "What language model would you like to try?",
#     ("Swedish", "Norwegian", "Danish", "Nordic"))

gpt_models = ["birgermoell/swedish-gpt", "flax-community/swe-gpt-wiki", "flax-community/nordic-gpt-wiki", "flax-community/norsk-gpt-wiki", "flax-community/dansk-gpt-wiki"]

selected_model = st.selectbox(
    "What language model would you like to try?",
    (gpt_models))

tokenizer = AutoTokenizer.from_pretrained(selected_model)
model = AutoModelWithLMHead.from_pretrained(selected_model)

generator = pipeline('text-generation', model=model, tokenizer=tokenizer)


st.title('GPT text generering')
desc = "Pröva GPT-modeller på flera språk. Skriv text nedanför för att utvärdera. Använder " + selected_model + " för att generera text. " + "Här kan du läsa mer om modellen https://huggingface.co/" + selected_model

st.write(desc)

num_sentences = st.number_input('Number of Characters', min_value=1, max_value=150, value=75)
user_input = st.text_input('Fyll i text att generera ifrån')


if st.button('Generate Text'):
    generated_text = generator(user_input, max_length=num_sentences, num_return_sequences=1)
    st.write(generated_text[0]["generated_text"])