Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import google.generativeai as genai
|
|
3 |
import os
|
4 |
from pypdf import PdfReader
|
5 |
|
6 |
-
#
|
7 |
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
8 |
if not GOOGLE_API_KEY:
|
9 |
raise ValueError("La variable de entorno GOOGLE_API_KEY no está definida.")
|
@@ -37,20 +37,21 @@ def process_input(instruction, text_file, pdf_file, image_file):
|
|
37 |
prompt_parts.append(f"Contenido del archivo PDF:\n{file_content}")
|
38 |
|
39 |
if image_file:
|
40 |
-
#
|
41 |
-
|
42 |
-
response = genai.
|
43 |
-
model="gemini-1.5-flash",
|
44 |
-
|
|
|
45 |
)
|
46 |
-
return response['
|
47 |
|
48 |
if prompt_parts:
|
49 |
prompt = "\n\n".join(prompt_parts)
|
50 |
response = genai.ChatCompletion.create(
|
51 |
-
model="gemini-1.5-flash",
|
52 |
messages=[{"role": "user", "content": prompt}],
|
53 |
-
max_tokens=8192
|
54 |
)
|
55 |
return response['choices'][0]['message']['content']
|
56 |
else:
|
@@ -62,7 +63,7 @@ iface = gr.Interface(
|
|
62 |
gr.Textbox(label="Instrucciones"),
|
63 |
gr.File(label="Archivo de Texto (.txt)"),
|
64 |
gr.File(label="Archivo PDF (.pdf)"),
|
65 |
-
gr.Image(label="Imagen", type="
|
66 |
],
|
67 |
outputs=gr.Textbox(label="Respuesta de Gemini"),
|
68 |
title="Interactúa con Gemini",
|
|
|
3 |
import os
|
4 |
from pypdf import PdfReader
|
5 |
|
6 |
+
# Cargar la clave API desde el entorno
|
7 |
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY")
|
8 |
if not GOOGLE_API_KEY:
|
9 |
raise ValueError("La variable de entorno GOOGLE_API_KEY no está definida.")
|
|
|
37 |
prompt_parts.append(f"Contenido del archivo PDF:\n{file_content}")
|
38 |
|
39 |
if image_file:
|
40 |
+
# Para el modelo vision, necesitas pasar la imagen como datos
|
41 |
+
prompt_parts.append(f"Imagen: {image_file.name}")
|
42 |
+
response = genai.ChatCompletion.create(
|
43 |
+
model="gemini-1.5-flash",
|
44 |
+
messages=[{"role": "user", "content": "Contenido de la imagen: " + image_file.name}],
|
45 |
+
max_tokens=8192,
|
46 |
)
|
47 |
+
return response['choices'][0]['message']['content']
|
48 |
|
49 |
if prompt_parts:
|
50 |
prompt = "\n\n".join(prompt_parts)
|
51 |
response = genai.ChatCompletion.create(
|
52 |
+
model="gemini-1.5-flash",
|
53 |
messages=[{"role": "user", "content": prompt}],
|
54 |
+
max_tokens=8192,
|
55 |
)
|
56 |
return response['choices'][0]['message']['content']
|
57 |
else:
|
|
|
63 |
gr.Textbox(label="Instrucciones"),
|
64 |
gr.File(label="Archivo de Texto (.txt)"),
|
65 |
gr.File(label="Archivo PDF (.pdf)"),
|
66 |
+
gr.Image(label="Imagen", type="filepath"), # Cambié el tipo a 'filepath'
|
67 |
],
|
68 |
outputs=gr.Textbox(label="Respuesta de Gemini"),
|
69 |
title="Interactúa con Gemini",
|