Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -9,8 +9,6 @@ if not GOOGLE_API_KEY:
|
|
9 |
raise ValueError("La variable de entorno GOOGLE_API_KEY no está definida.")
|
10 |
|
11 |
genai.configure(api_key=GOOGLE_API_KEY)
|
12 |
-
model_text = genai.GenerativeModel('gemini-pro')
|
13 |
-
model_vision = genai.GenerativeModel('gemini-pro-vision')
|
14 |
|
15 |
def read_text_file(filepath):
|
16 |
with open(filepath, 'r', encoding='utf-8') as f:
|
@@ -39,15 +37,22 @@ def process_input(instruction, text_file, pdf_file, image_file):
|
|
39 |
prompt_parts.append(f"Contenido del archivo PDF:\n{file_content}")
|
40 |
|
41 |
if image_file:
|
42 |
-
#
|
43 |
-
|
44 |
-
response =
|
45 |
-
|
|
|
|
|
|
|
46 |
|
47 |
if prompt_parts:
|
48 |
prompt = "\n\n".join(prompt_parts)
|
49 |
-
response =
|
50 |
-
|
|
|
|
|
|
|
|
|
51 |
else:
|
52 |
return "Por favor, proporciona alguna instrucción o archivo."
|
53 |
|
@@ -57,11 +62,11 @@ iface = gr.Interface(
|
|
57 |
gr.Textbox(label="Instrucciones"),
|
58 |
gr.File(label="Archivo de Texto (.txt)"),
|
59 |
gr.File(label="Archivo PDF (.pdf)"),
|
60 |
-
gr.Image(label="Imagen"),
|
61 |
],
|
62 |
outputs=gr.Textbox(label="Respuesta de Gemini"),
|
63 |
title="Interactúa con Gemini",
|
64 |
description="Sube archivos de texto, PDF o imágenes y proporciona instrucciones para que Gemini los procese.",
|
65 |
)
|
66 |
|
67 |
-
iface.launch()
|
|
|
9 |
raise ValueError("La variable de entorno GOOGLE_API_KEY no está definida.")
|
10 |
|
11 |
genai.configure(api_key=GOOGLE_API_KEY)
|
|
|
|
|
12 |
|
13 |
def read_text_file(filepath):
|
14 |
with open(filepath, 'r', encoding='utf-8') as f:
|
|
|
37 |
prompt_parts.append(f"Contenido del archivo PDF:\n{file_content}")
|
38 |
|
39 |
if image_file:
|
40 |
+
# Aquí debes trabajar con la API de imágenes
|
41 |
+
image_data = image_file # Usamos directamente la imagen cargada
|
42 |
+
response = genai.ImageGeneration.create(
|
43 |
+
model="gemini-1.5-flash", # Usamos siempre el modelo correcto
|
44 |
+
image=image_data
|
45 |
+
)
|
46 |
+
return response['image'] # Asumiendo que la respuesta devuelve una imagen procesada
|
47 |
|
48 |
if prompt_parts:
|
49 |
prompt = "\n\n".join(prompt_parts)
|
50 |
+
response = genai.ChatCompletion.create(
|
51 |
+
model="gemini-1.5-flash", # Usamos siempre el modelo correcto
|
52 |
+
messages=[{"role": "user", "content": prompt}],
|
53 |
+
max_tokens=8192 # Cambié a 8192 tokens
|
54 |
+
)
|
55 |
+
return response['choices'][0]['message']['content']
|
56 |
else:
|
57 |
return "Por favor, proporciona alguna instrucción o archivo."
|
58 |
|
|
|
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="file"), # Cambié el tipo de 'image' a 'file'
|
66 |
],
|
67 |
outputs=gr.Textbox(label="Respuesta de Gemini"),
|
68 |
title="Interactúa con Gemini",
|
69 |
description="Sube archivos de texto, PDF o imágenes y proporciona instrucciones para que Gemini los procese.",
|
70 |
)
|
71 |
|
72 |
+
iface.launch()
|