Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,21 +2,16 @@ import streamlit as st
|
|
| 2 |
import os
|
| 3 |
import google.generativeai as genai
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
-
import fitz
|
| 6 |
|
| 7 |
-
# Cargar variables de entorno
|
| 8 |
load_dotenv()
|
| 9 |
|
| 10 |
-
# Obtener API Key de Gemini
|
| 11 |
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 12 |
|
| 13 |
-
# Configurar la API de Gemini
|
| 14 |
genai.configure(api_key=GEMINI_API_KEY)
|
| 15 |
|
| 16 |
-
# Modelo de Gemini
|
| 17 |
MODEL_NAME = "gemini-2.5-pro-exp-03-25"
|
| 18 |
|
| 19 |
-
# Función para generar contenido con Gemini
|
| 20 |
def generate_response(user_input):
|
| 21 |
try:
|
| 22 |
model = genai.GenerativeModel(MODEL_NAME)
|
|
@@ -25,7 +20,6 @@ def generate_response(user_input):
|
|
| 25 |
except Exception as e:
|
| 26 |
return f"Error en la generación de contenido: {str(e)}"
|
| 27 |
|
| 28 |
-
# Función para extraer texto de un PDF
|
| 29 |
def extract_text_from_pdf(pdf_file):
|
| 30 |
try:
|
| 31 |
doc = fitz.open(stream=pdf_file.read(), filetype="pdf")
|
|
@@ -34,17 +28,13 @@ def extract_text_from_pdf(pdf_file):
|
|
| 34 |
except Exception as e:
|
| 35 |
return f"Error al leer el PDF: {str(e)}"
|
| 36 |
|
| 37 |
-
# Interfaz con Streamlit
|
| 38 |
st.set_page_config(page_title="Generador con Gemini API", layout="centered")
|
| 39 |
st.title("Chat con Gemini API")
|
| 40 |
|
| 41 |
-
# Entrada del usuario (texto manual)
|
| 42 |
user_input = st.text_area("Escribe algo:", "")
|
| 43 |
|
| 44 |
-
# Opción para subir un archivo PDF
|
| 45 |
uploaded_file = st.file_uploader("📄 O sube un PDF", type=["pdf"])
|
| 46 |
|
| 47 |
-
# Botón para generar respuesta
|
| 48 |
if st.button("Generar respuesta"):
|
| 49 |
if uploaded_file:
|
| 50 |
st.write("⏳ Extrayendo texto del PDF...")
|
|
@@ -59,4 +49,3 @@ if st.button("Generar respuesta"):
|
|
| 59 |
st.write(response)
|
| 60 |
else:
|
| 61 |
st.warning("⚠️ Ingresa un texto o sube un PDF antes de continuar.")
|
| 62 |
-
|
|
|
|
| 2 |
import os
|
| 3 |
import google.generativeai as genai
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
+
import fitz
|
| 6 |
|
|
|
|
| 7 |
load_dotenv()
|
| 8 |
|
|
|
|
| 9 |
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 10 |
|
|
|
|
| 11 |
genai.configure(api_key=GEMINI_API_KEY)
|
| 12 |
|
|
|
|
| 13 |
MODEL_NAME = "gemini-2.5-pro-exp-03-25"
|
| 14 |
|
|
|
|
| 15 |
def generate_response(user_input):
|
| 16 |
try:
|
| 17 |
model = genai.GenerativeModel(MODEL_NAME)
|
|
|
|
| 20 |
except Exception as e:
|
| 21 |
return f"Error en la generación de contenido: {str(e)}"
|
| 22 |
|
|
|
|
| 23 |
def extract_text_from_pdf(pdf_file):
|
| 24 |
try:
|
| 25 |
doc = fitz.open(stream=pdf_file.read(), filetype="pdf")
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
return f"Error al leer el PDF: {str(e)}"
|
| 30 |
|
|
|
|
| 31 |
st.set_page_config(page_title="Generador con Gemini API", layout="centered")
|
| 32 |
st.title("Chat con Gemini API")
|
| 33 |
|
|
|
|
| 34 |
user_input = st.text_area("Escribe algo:", "")
|
| 35 |
|
|
|
|
| 36 |
uploaded_file = st.file_uploader("📄 O sube un PDF", type=["pdf"])
|
| 37 |
|
|
|
|
| 38 |
if st.button("Generar respuesta"):
|
| 39 |
if uploaded_file:
|
| 40 |
st.write("⏳ Extrayendo texto del PDF...")
|
|
|
|
| 49 |
st.write(response)
|
| 50 |
else:
|
| 51 |
st.warning("⚠️ Ingresa un texto o sube un PDF antes de continuar.")
|
|
|