Spaces:
Sleeping
Sleeping
Create Generador_frases
Browse files- pages/Generador_frases +96 -0
pages/Generador_frases
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
import os
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
# Configuraci贸n de la clave API
|
| 7 |
+
load_dotenv()
|
| 8 |
+
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 9 |
+
IMAGE_GENERATION_API_KEY = os.getenv("IMAGE_GENERATION_API_KEY")
|
| 10 |
+
|
| 11 |
+
# Funci贸n para obtener una frase relacionada usando el modelo Gemini Advanced
|
| 12 |
+
def obtener_frase_relacionada(versiculo):
|
| 13 |
+
headers = {
|
| 14 |
+
"Authorization": f"Bearer {GEMINI_API_KEY}",
|
| 15 |
+
"Content-Type": "application/json"
|
| 16 |
+
}
|
| 17 |
+
data = {
|
| 18 |
+
"prompt": versiculo,
|
| 19 |
+
"model": "gemini-advanced"
|
| 20 |
+
}
|
| 21 |
+
response = requests.post("https://api.gemini-advanced.com/v1/generate", headers=headers, json=data)
|
| 22 |
+
if response.status_code == 200:
|
| 23 |
+
return response.json()["response"]
|
| 24 |
+
else:
|
| 25 |
+
st.error("Error al obtener la frase relacionada")
|
| 26 |
+
return None
|
| 27 |
+
|
| 28 |
+
# Funci贸n para generar una imagen alusiva usando un servicio de generaci贸n de im谩genes
|
| 29 |
+
def generar_imagen(frase):
|
| 30 |
+
headers = {
|
| 31 |
+
"Authorization": f"Bearer {IMAGE_GENERATION_API_KEY}",
|
| 32 |
+
"Content-Type": "application/json"
|
| 33 |
+
}
|
| 34 |
+
data = {
|
| 35 |
+
"prompt": frase,
|
| 36 |
+
"model": "image-generation-model"
|
| 37 |
+
}
|
| 38 |
+
response = requests.post("https://api.image-generation.com/v1/generate", headers=headers, json=data)
|
| 39 |
+
if response.status_code == 200:
|
| 40 |
+
return response.json()["image_url"]
|
| 41 |
+
else:
|
| 42 |
+
st.error("Error al generar la imagen")
|
| 43 |
+
return None
|
| 44 |
+
|
| 45 |
+
# Configuraci贸n de Streamlit
|
| 46 |
+
st.set_page_config(page_title="Generador de Frases B铆blicas", page_icon="馃摐")
|
| 47 |
+
|
| 48 |
+
# Estilos CSS personalizados
|
| 49 |
+
st.markdown(
|
| 50 |
+
"""
|
| 51 |
+
<style>
|
| 52 |
+
body {
|
| 53 |
+
background: linear-gradient(to right, #f2f3f5, #ffcccb);
|
| 54 |
+
color: #333;
|
| 55 |
+
}
|
| 56 |
+
.stButton>button {
|
| 57 |
+
background-color: #4CAF50;
|
| 58 |
+
color: white;
|
| 59 |
+
border-radius: 10px;
|
| 60 |
+
}
|
| 61 |
+
.stTextInput>div>div>input {
|
| 62 |
+
border: 1px solid #4CAF50;
|
| 63 |
+
border-radius: 10px;
|
| 64 |
+
}
|
| 65 |
+
.stMarkdown>div>p {
|
| 66 |
+
color: #4CAF50;
|
| 67 |
+
font-weight: bold;
|
| 68 |
+
}
|
| 69 |
+
</style>
|
| 70 |
+
""",
|
| 71 |
+
unsafe_allow_html=True,
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
# Encabezado
|
| 75 |
+
st.image("biblie.jpg")
|
| 76 |
+
st.title("馃摐 Generador de Frases B铆blicas")
|
| 77 |
+
st.markdown("Escribe un vers铆culo o una palabra y obt茅n una frase relacionada de personajes b铆blicos y santos, junto con una imagen alusiva.")
|
| 78 |
+
|
| 79 |
+
# Entrada de texto para el vers铆culo o palabra
|
| 80 |
+
versiculo_usuario = st.text_input("Escribe un vers铆culo o una palabra:")
|
| 81 |
+
|
| 82 |
+
if st.button("Generar"):
|
| 83 |
+
if versiculo_usuario:
|
| 84 |
+
with st.spinner("Generando frase..."):
|
| 85 |
+
frase_relacionada = obtener_frase_relacionada(versiculo_usuario)
|
| 86 |
+
if frase_relacionada:
|
| 87 |
+
st.subheader("Frase relacionada:")
|
| 88 |
+
st.markdown(frase_relacionada)
|
| 89 |
+
|
| 90 |
+
with st.spinner("Generando imagen..."):
|
| 91 |
+
imagen_url = generar_imagen(frase_relacionada)
|
| 92 |
+
if imagen_url:
|
| 93 |
+
st.subheader("Imagen alusiva:")
|
| 94 |
+
st.image(imagen_url)
|
| 95 |
+
else:
|
| 96 |
+
st.warning("Por favor, ingresa un vers铆culo o una palabra antes de generar.")
|