johnometalman commited on
Commit
e486e1b
1 Parent(s): ca2ea04

manejo de secrets para el modelo

Browse files
Files changed (6) hide show
  1. .env-example +2 -0
  2. .gitignore +3 -0
  3. __pycache__/utils.cpython-38.pyc +0 -0
  4. app.py +11 -0
  5. requirements.txt +1 -0
  6. utils.py +9 -4
.env-example ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ HF_AUTH_TOKEN=your_huggingface_token
2
+ API_KEY=your_api_key
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ venv/
2
+ .env
3
+ test.py
__pycache__/utils.cpython-38.pyc DELETED
Binary file (902 Bytes)
 
app.py CHANGED
@@ -1,7 +1,18 @@
1
  import streamlit as st
2
  from utils import carga_modelo, genera
 
3
  import os
4
 
 
 
 
 
 
 
 
 
 
 
5
  # P谩gina principal
6
  st.title('Generador de Mariposas')
7
  st.write('Este es un modelo light GAN entrenado para generaci贸n de mariposas')
 
1
  import streamlit as st
2
  from utils import carga_modelo, genera
3
+ from dotenv import load_dotenv
4
  import os
5
 
6
+ # Load environment variables from .env
7
+ load_dotenv()
8
+
9
+ # Access the variables
10
+ token = os.getenv("HF_AUTH_TOKEN")
11
+ api_key = os.getenv("API_KEY")
12
+ repo_id = 'ceyda/butterfly_cropped_uniq1K_512'
13
+ modelo_gan = carga_modelo(repo_id, token)
14
+
15
+
16
  # P谩gina principal
17
  st.title('Generador de Mariposas')
18
  st.write('Este es un modelo light GAN entrenado para generaci贸n de mariposas')
requirements.txt CHANGED
@@ -1,5 +1,6 @@
1
  git+https://github.com/huggingface/community-events.git@3fea10c5d5a50c69f509e34cd580fe9139905d04#egg=huggan
2
  transformers
 
3
 
4
  # faiss-cpu
5
  # paddlehub
 
1
  git+https://github.com/huggingface/community-events.git@3fea10c5d5a50c69f509e34cd580fe9139905d04#egg=huggan
2
  transformers
3
+ python-dotenv
4
 
5
  # faiss-cpu
6
  # paddlehub
utils.py CHANGED
@@ -1,13 +1,18 @@
1
  import numpy as np
2
  import torch
3
  from huggan.pytorch.lightweight_gan.lightweight_gan import LightweightGAN
 
4
 
5
 
6
  ## Cargamos el modelo desde el Hub de Hugging Face
7
- def carga_modelo(model_name='ceyda/butterfly_cropped_uniq1K_512', model_version=None):
8
- gan = LightweightGAN.from_pretrained(model_name, version=model_version)
9
- gan.eval()
10
- return gan
 
 
 
 
11
 
12
  def genera(gan, batch_size=1):
13
  with torch.no_grad():
 
1
  import numpy as np
2
  import torch
3
  from huggan.pytorch.lightweight_gan.lightweight_gan import LightweightGAN
4
+ from transformers import AutoModel
5
 
6
 
7
  ## Cargamos el modelo desde el Hub de Hugging Face
8
+ def carga_modelo(repo_id, token):
9
+ return AutoModel.from_pretrained(repo_id, use_auth_token=token)
10
+
11
+
12
+ # def carga_modelo(model_name='ceyda/butterfly_cropped_uniq1K_512', model_version=None):
13
+ # gan = LightweightGAN.from_pretrained(model_name, version=model_version)
14
+ # gan.eval()
15
+ # return gan
16
 
17
  def genera(gan, batch_size=1):
18
  with torch.no_grad():