ErikDaska commited on
Commit
9ccf6e6
·
verified ·
1 Parent(s): 21518fc

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +6 -2
src/streamlit_app.py CHANGED
@@ -1,6 +1,10 @@
1
  import streamlit as st
2
  import transformers
3
  from transformers import pipeline
 
 
 
 
4
 
5
  def infer(sent, max_length, num_return_sequences):
6
  generator = pipeline('text-generation', model='gpt2')
@@ -8,12 +12,12 @@ def infer(sent, max_length, num_return_sequences):
8
  return generator(sent, max_length=max_length, num_return_sequences=num_return_sequences)
9
 
10
  def instantiate_gpt2(max_length_ : int, num_return_sequences : int, text : str) -> dict:
11
- pipe = pipeline(task='text-generation', model='Iscte-Sintra/GPT2-Kriolu')
12
  results = pipe(text, max_length=max_length_, num_return_sequences=num_return_sequences)
13
  return results
14
 
15
  def instantiate_roberta(top_k : int, text : str) -> dict:
16
- pipe = pipeline("fill-mask", model="Iscte-Sintra/RoBERTa-Kriolu")
17
  return pipe(text, top_k=top_k)
18
 
19
  def build_gpt2_page():
 
1
  import streamlit as st
2
  import transformers
3
  from transformers import pipeline
4
+ import os
5
+
6
+ # Read token from environment (set as secret in Space settings)
7
+ token = os.environ.get("token")
8
 
9
  def infer(sent, max_length, num_return_sequences):
10
  generator = pipeline('text-generation', model='gpt2')
 
12
  return generator(sent, max_length=max_length, num_return_sequences=num_return_sequences)
13
 
14
  def instantiate_gpt2(max_length_ : int, num_return_sequences : int, text : str) -> dict:
15
+ pipe = pipeline(task='text-generation', model='Iscte-Sintra/GPT2-Kriolu', token=token)
16
  results = pipe(text, max_length=max_length_, num_return_sequences=num_return_sequences)
17
  return results
18
 
19
  def instantiate_roberta(top_k : int, text : str) -> dict:
20
+ pipe = pipeline("fill-mask", model="Iscte-Sintra/RoBERTa-Kriolu", token=token)
21
  return pipe(text, top_k=top_k)
22
 
23
  def build_gpt2_page():