Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,8 +5,9 @@ import time
|
|
| 5 |
import base64
|
| 6 |
import random
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
-
from google.cloud import texttospeech
|
| 9 |
from google.auth import default
|
|
|
|
| 10 |
import PyPDF2
|
| 11 |
from fpdf import FPDF
|
| 12 |
import tempfile
|
|
@@ -109,17 +110,26 @@ page = st.sidebar.selectbox("Selecciona una p谩gina", ["P谩gina Principal", "Cha
|
|
| 109 |
|
| 110 |
# Inicializar el cliente de Vertex AI
|
| 111 |
credentials, _ = default()
|
| 112 |
-
|
|
|
|
| 113 |
|
| 114 |
# Funci贸n para generar im谩genes con Vertex AI
|
| 115 |
def generar_imagen_vertex(prompt):
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
# Funci贸n para generar texto con Vertex AI
|
| 120 |
def generar_texto_vertex(prompt):
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
# Funci贸n para generar reflexi贸n usando Vertex AI
|
| 125 |
def generar_reflexion(keyword):
|
|
@@ -140,7 +150,7 @@ def text_to_speech_base64(text):
|
|
| 140 |
def obtener_audio_aleatorio():
|
| 141 |
carpeta_reflexiones = "reflexiones" # Cambia esta ruta por la correcta
|
| 142 |
archivos = os.listdir(carpeta_reflexiones)
|
| 143 |
-
archivos_mp3 = [archivo for archivo in archivos
|
| 144 |
if archivos_mp3:
|
| 145 |
audio_seleccionado = random.choice(archivos_mp3)
|
| 146 |
with open(os.path.join(carpeta_reflexiones, audio_seleccionado), "rb") as audio_file:
|
|
@@ -344,6 +354,3 @@ elif page == "Diario Reflexivo":
|
|
| 344 |
file_name="diario_reflexivo.pdf",
|
| 345 |
mime="application/pdf"
|
| 346 |
)
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
|
|
|
| 5 |
import base64
|
| 6 |
import random
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
+
from google.cloud import texttospeech
|
| 9 |
from google.auth import default
|
| 10 |
+
from google.cloud import aiplatform_v1
|
| 11 |
import PyPDF2
|
| 12 |
from fpdf import FPDF
|
| 13 |
import tempfile
|
|
|
|
| 110 |
|
| 111 |
# Inicializar el cliente de Vertex AI
|
| 112 |
credentials, _ = default()
|
| 113 |
+
client_options = {"api_endpoint": f"{location}-aiplatform.googleapis.com"}
|
| 114 |
+
client = aiplatform_v1.PredictionServiceClient(client_options=client_options)
|
| 115 |
|
| 116 |
# Funci贸n para generar im谩genes con Vertex AI
|
| 117 |
def generar_imagen_vertex(prompt):
|
| 118 |
+
endpoint = f"projects/{project_id}/locations/{location}/endpoints/YOUR_IMAGE_GENERATION_ENDPOINT_ID"
|
| 119 |
+
instance = {"prompt": prompt}
|
| 120 |
+
instances = [instance]
|
| 121 |
+
parameters = {}
|
| 122 |
+
response = client.predict(endpoint=endpoint, instances=instances, parameters=parameters)
|
| 123 |
+
return response.predictions[0]['generated_image_uri']
|
| 124 |
|
| 125 |
# Funci贸n para generar texto con Vertex AI
|
| 126 |
def generar_texto_vertex(prompt):
|
| 127 |
+
endpoint = f"projects/{project_id}/locations/{location}/endpoints/YOUR_TEXT_GENERATION_ENDPOINT_ID"
|
| 128 |
+
instance = {"prompt": prompt}
|
| 129 |
+
instances = [instance]
|
| 130 |
+
parameters = {}
|
| 131 |
+
response = client.predict(endpoint=endpoint, instances=instances, parameters=parameters)
|
| 132 |
+
return response.predictions[0]['generated_text']
|
| 133 |
|
| 134 |
# Funci贸n para generar reflexi贸n usando Vertex AI
|
| 135 |
def generar_reflexion(keyword):
|
|
|
|
| 150 |
def obtener_audio_aleatorio():
|
| 151 |
carpeta_reflexiones = "reflexiones" # Cambia esta ruta por la correcta
|
| 152 |
archivos = os.listdir(carpeta_reflexiones)
|
| 153 |
+
archivos_mp3 = [archivo for archivo in archivos si archivo.endswith(".mp3")]
|
| 154 |
if archivos_mp3:
|
| 155 |
audio_seleccionado = random.choice(archivos_mp3)
|
| 156 |
with open(os.path.join(carpeta_reflexiones, audio_seleccionado), "rb") as audio_file:
|
|
|
|
| 354 |
file_name="diario_reflexivo.pdf",
|
| 355 |
mime="application/pdf"
|
| 356 |
)
|
|
|
|
|
|
|
|
|