rmayormartins
commited on
Commit
·
89073fe
1
Parent(s):
ae93803
Subindo arquivos33131
Browse files- app.py +4 -7
- requirements.txt +0 -1
app.py
CHANGED
@@ -5,15 +5,12 @@ from PIL import Image
|
|
5 |
from gtts import gTTS
|
6 |
import numpy as np
|
7 |
import cv2
|
8 |
-
from transformers import BlipProcessor, BlipForConditionalGeneration,
|
9 |
from huggingface_hub import login
|
10 |
|
11 |
# Ler o token da variável de ambiente
|
12 |
hf_token = os.getenv("HUGGINGFACE_TOKEN")
|
13 |
|
14 |
-
# Depuração: Verifique se o token está sendo lido corretamente
|
15 |
-
print(f"Token lido: {hf_token}")
|
16 |
-
|
17 |
if hf_token:
|
18 |
login(token=hf_token)
|
19 |
|
@@ -52,9 +49,9 @@ def describe_image(image):
|
|
52 |
|
53 |
# Função para traduzir descrição para português
|
54 |
def translate_description(description):
|
55 |
-
model_name = 'Helsinki-NLP/opus-mt-en-pt'
|
56 |
-
tokenizer =
|
57 |
-
model =
|
58 |
translated = model.generate(**tokenizer(description, return_tensors="pt", padding=True))
|
59 |
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
60 |
return translated_text
|
|
|
5 |
from gtts import gTTS
|
6 |
import numpy as np
|
7 |
import cv2
|
8 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration, AutoTokenizer, AutoModelForSeq2SeqLM
|
9 |
from huggingface_hub import login
|
10 |
|
11 |
# Ler o token da variável de ambiente
|
12 |
hf_token = os.getenv("HUGGINGFACE_TOKEN")
|
13 |
|
|
|
|
|
|
|
14 |
if hf_token:
|
15 |
login(token=hf_token)
|
16 |
|
|
|
49 |
|
50 |
# Função para traduzir descrição para português
|
51 |
def translate_description(description):
|
52 |
+
model_name = 'Helsinki-NLP/opus-mt-tc-big-en-pt'
|
53 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
54 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
55 |
translated = model.generate(**tokenizer(description, return_tensors="pt", padding=True))
|
56 |
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
57 |
return translated_text
|
requirements.txt
CHANGED
@@ -7,4 +7,3 @@ transformers
|
|
7 |
gtts
|
8 |
sentencepiece
|
9 |
huggingface_hub
|
10 |
-
|
|
|
7 |
gtts
|
8 |
sentencepiece
|
9 |
huggingface_hub
|
|