Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,13 +9,16 @@ import PyPDF2
|
|
| 9 |
from fpdf import FPDF
|
| 10 |
import tempfile
|
| 11 |
import requests
|
| 12 |
-
from groq import Groq # Aseg煤rate de tener instalada la librer铆a groq
|
| 13 |
|
| 14 |
# Cargar variables de entorno desde el archivo .env
|
| 15 |
load_dotenv()
|
| 16 |
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "botidinamix-g.json"
|
| 17 |
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
# Configuraci贸n de Streamlit
|
| 20 |
st.set_page_config(page_title="Asistente Teol贸gico", page_icon="馃摉")
|
| 21 |
|
|
@@ -137,23 +140,26 @@ def obtener_respuesta(pregunta, contexto="", modelo="llama3-8b-8192", temperatur
|
|
| 137 |
return "Lo siento, la pregunta no puede estar vac铆a."
|
| 138 |
|
| 139 |
try:
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
| 157 |
except Exception as e:
|
| 158 |
st.error(f"Error al comunicarse con Groq: {e}")
|
| 159 |
return "Lo siento, no puedo procesar tu solicitud en este momento."
|
|
|
|
| 9 |
from fpdf import FPDF
|
| 10 |
import tempfile
|
| 11 |
import requests
|
|
|
|
| 12 |
|
| 13 |
# Cargar variables de entorno desde el archivo .env
|
| 14 |
load_dotenv()
|
| 15 |
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "botidinamix-g.json"
|
| 16 |
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 17 |
|
| 18 |
+
# Verifica que la clave API de Groq est茅 configurada
|
| 19 |
+
if not groq_api_key:
|
| 20 |
+
st.error("No API key provided for Groq. Please set your API key in the .env file.")
|
| 21 |
+
|
| 22 |
# Configuraci贸n de Streamlit
|
| 23 |
st.set_page_config(page_title="Asistente Teol贸gico", page_icon="馃摉")
|
| 24 |
|
|
|
|
| 140 |
return "Lo siento, la pregunta no puede estar vac铆a."
|
| 141 |
|
| 142 |
try:
|
| 143 |
+
headers = {
|
| 144 |
+
"Authorization": f"Bearer {groq_api_key}",
|
| 145 |
+
"Content-Type": "application/json"
|
| 146 |
+
}
|
| 147 |
+
data = {
|
| 148 |
+
"messages": [
|
| 149 |
+
{"role": "system", "content": contexto},
|
| 150 |
+
{"role": "user", "content": pregunta}
|
| 151 |
+
],
|
| 152 |
+
"model": modelo,
|
| 153 |
+
"temperature": temperatura,
|
| 154 |
+
"max_tokens": 1024,
|
| 155 |
+
"top_p": 1,
|
| 156 |
+
"stop": None,
|
| 157 |
+
"stream": False
|
| 158 |
+
}
|
| 159 |
+
response = requests.post("https://api.groq.com/v1/completions", headers=headers, json=data)
|
| 160 |
+
response.raise_for_status()
|
| 161 |
+
result = response.json()
|
| 162 |
+
return result['choices'][0]['message']['content'].strip()
|
| 163 |
except Exception as e:
|
| 164 |
st.error(f"Error al comunicarse con Groq: {e}")
|
| 165 |
return "Lo siento, no puedo procesar tu solicitud en este momento."
|