csaguiar commited on
Commit
a8d3972
1 Parent(s): ffbccaa

adding token access

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -1,24 +1,34 @@
1
  import os
 
2
  import streamlit as st
3
  from diffusers import StableDiffusionPipeline
4
  from transformers import MBart50TokenizerFast, MBartForConditionalGeneration
5
 
6
  DIFFUSION_MODEL_ID = "runwayml/stable-diffusion-v1-5"
7
  TRANSLATION_MODEL_ID = "Narrativa/mbart-large-50-finetuned-opus-pt-en-translation" # noqa
8
- DEVICE_NAME = os.getenv("DEVICE_NAME", "cuda")
 
9
 
10
 
11
  def load_translation_models(translation_model_id):
12
- tokenizer = MBart50TokenizerFast.from_pretrained(translation_model_id)
 
 
 
13
  tokenizer.src_lang = 'pt_XX'
14
- text_model = \
15
- MBartForConditionalGeneration.from_pretrained(translation_model_id)
 
 
16
 
17
  return tokenizer, text_model
18
 
19
 
20
  def pipeline_generate(diffusion_model_id):
21
- pipe = StableDiffusionPipeline.from_pretrained(diffusion_model_id)
 
 
 
22
  pipe = pipe.to(DEVICE_NAME)
23
 
24
  # Recommended if your computer has < 64 GB of RAM
 
1
  import os
2
+ import torch
3
  import streamlit as st
4
  from diffusers import StableDiffusionPipeline
5
  from transformers import MBart50TokenizerFast, MBartForConditionalGeneration
6
 
7
  DIFFUSION_MODEL_ID = "runwayml/stable-diffusion-v1-5"
8
  TRANSLATION_MODEL_ID = "Narrativa/mbart-large-50-finetuned-opus-pt-en-translation" # noqa
9
+ DEVICE_NAME = os.getenv("DEVICE_NAME", "cpu")
10
+ HUGGING_FACE_TOKEN = os.getenv("HUGGING_FACE_TOKEN")
11
 
12
 
13
  def load_translation_models(translation_model_id):
14
+ tokenizer = MBart50TokenizerFast.from_pretrained(
15
+ translation_model_id,
16
+ use_auth_token=HUGGING_FACE_TOKEN
17
+ )
18
  tokenizer.src_lang = 'pt_XX'
19
+ text_model = MBartForConditionalGeneration.from_pretrained(
20
+ translation_model_id,
21
+ use_auth_token=HUGGING_FACE_TOKEN
22
+ )
23
 
24
  return tokenizer, text_model
25
 
26
 
27
  def pipeline_generate(diffusion_model_id):
28
+ pipe = StableDiffusionPipeline.from_pretrained(
29
+ diffusion_model_id, torch_dtype=torch.float16, revision="fp16",
30
+ use_auth_token=HUGGING_FACE_TOKEN
31
+ )
32
  pipe = pipe.to(DEVICE_NAME)
33
 
34
  # Recommended if your computer has < 64 GB of RAM