birgermoell commited on
Commit
b7851ed
1 Parent(s): 0f85201

Updated model

Browse files
Files changed (3) hide show
  1. app.py +34 -2
  2. evaluate.py +8 -0
  3. requirements.txt +2 -0
app.py CHANGED
@@ -1,4 +1,36 @@
1
  import streamlit as st
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import GPT2Tokenizer, GPT2Model, FlaxGPT2LMHeadModel, GPT2LMHeadModel, pipeline, set_seed
3
+ import torch
4
 
5
+ #===========================================#
6
+ # Loads Model and Pipeline #
7
+ #===========================================#
8
+
9
+ from transformers import GPT2Tokenizer, GPT2Model, FlaxGPT2LMHeadModel, GPT2LMHeadModel, pipeline, set_seed
10
+
11
+ tokenizer = AutoTokenizer.from_pretrained("flax-community/swe-gpt-wiki")
12
+ model = AutoModelWithLMHead.from_pretrained("flax-community/swe-gpt-wiki")
13
+
14
+ generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
15
+ set_seed(42)
16
+
17
+
18
+ #===========================================#
19
+ # Streamlit Code #
20
+ #===========================================#
21
+ desc = "En svensk GPT-modell tränad på wikipedia"
22
+
23
+ st.title('Vi använder wikipidea för att generera text')
24
+ st.write(desc)
25
+
26
+ num_sentences = st.number_input('Number of Sentences', min_value=1, max_value=20, value=5)
27
+ user_input = st.text_input('Seed Text (can leave blank)')
28
+
29
+
30
+ if st.button('Generate Text'):
31
+ generated_text = generator(user_input, max_length=num_sentences, num_return_sequences=1)
32
+ st.write(generated_text[0]["generated_text"])
33
+
34
+
35
+
36
+
evaluate.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from transformers import GPT2Tokenizer, GPT2Model, FlaxGPT2LMHeadModel, GPT2LMHeadModel, pipeline, set_seed
2
+
3
+ tokenizer = GPT2Tokenizer.from_pretrained("flax-community/swe-gpt-wiki")
4
+ model = GPT2LMHeadModel.from_pretrained("flax-community/swe-gpt-wiki")
5
+ generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
6
+ set_seed(42)
7
+ result = generator("Det var en", max_length=50, num_return_sequences=5)
8
+ print(result)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+ torch