Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,15 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
SUBTITLE = "Interactúa con nuestro modelo de AI para generar respuestas creativas" # Aquí pones tu subtítulo
|
4 |
|
5 |
import os
|
6 |
import time
|
7 |
import uuid
|
8 |
from typing import List, Tuple, Optional, Dict, Union
|
|
|
9 |
import google.generativeai as genai
|
10 |
import gradio as gr
|
11 |
from PIL import Image
|
12 |
from dotenv import load_dotenv
|
13 |
-
from langdetect import detect # Agregar para la detección del idioma
|
14 |
|
15 |
# Cargar las variables de entorno desde el archivo .env
|
16 |
load_dotenv()
|
@@ -73,11 +72,6 @@ def bot(
|
|
73 |
|
74 |
# Configurar la API con la clave
|
75 |
genai.configure(api_key=GOOGLE_API_KEY)
|
76 |
-
|
77 |
-
# Detectar el idioma del texto ingresado
|
78 |
-
text_prompt = [chatbot[-1][0]] if chatbot and chatbot[-1][0] and isinstance(chatbot[-1][0], str) else []
|
79 |
-
detected_language = detect(text_prompt[-1]) if text_prompt else 'en' # Detectar el idioma del texto
|
80 |
-
|
81 |
generation_config = genai.types.GenerationConfig(
|
82 |
temperature=temperature,
|
83 |
max_output_tokens=max_output_tokens,
|
@@ -86,10 +80,11 @@ def bot(
|
|
86 |
top_p=top_p
|
87 |
)
|
88 |
|
89 |
-
|
|
|
90 |
model_name = 'gemini-1.5-flash'
|
91 |
model = genai.GenerativeModel(model_name)
|
92 |
-
response = model.generate_content(text_prompt +
|
93 |
|
94 |
chatbot[-1][1] = ""
|
95 |
for chunk in response:
|
@@ -163,8 +158,8 @@ bot_inputs = [
|
|
163 |
]
|
164 |
|
165 |
with gr.Blocks() as demo:
|
166 |
-
gr.HTML(TITLE)
|
167 |
-
gr.HTML(SUBTITLE)
|
168 |
with gr.Column():
|
169 |
chatbot_component.render()
|
170 |
with gr.Row():
|
|
|
1 |
+
TITLE = """<h1 align="center">Gemini Playground 💬</h1>"""
|
2 |
+
SUBTITLE = """<h2 align="center">Play with Gemini Pro and Gemini Pro Vision</h2>"""
|
|
|
3 |
|
4 |
import os
|
5 |
import time
|
6 |
import uuid
|
7 |
from typing import List, Tuple, Optional, Dict, Union
|
8 |
+
|
9 |
import google.generativeai as genai
|
10 |
import gradio as gr
|
11 |
from PIL import Image
|
12 |
from dotenv import load_dotenv
|
|
|
13 |
|
14 |
# Cargar las variables de entorno desde el archivo .env
|
15 |
load_dotenv()
|
|
|
72 |
|
73 |
# Configurar la API con la clave
|
74 |
genai.configure(api_key=GOOGLE_API_KEY)
|
|
|
|
|
|
|
|
|
|
|
75 |
generation_config = genai.types.GenerationConfig(
|
76 |
temperature=temperature,
|
77 |
max_output_tokens=max_output_tokens,
|
|
|
80 |
top_p=top_p
|
81 |
)
|
82 |
|
83 |
+
text_prompt = [chatbot[-1][0]] if chatbot and chatbot[-1][0] and isinstance(chatbot[-1][0], str) else []
|
84 |
+
image_prompt = [preprocess_image(Image.open(file).convert('RGB')) for file in files] if files else []
|
85 |
model_name = 'gemini-1.5-flash'
|
86 |
model = genai.GenerativeModel(model_name)
|
87 |
+
response = model.generate_content(text_prompt + image_prompt, stream=True, generation_config=generation_config)
|
88 |
|
89 |
chatbot[-1][1] = ""
|
90 |
for chunk in response:
|
|
|
158 |
]
|
159 |
|
160 |
with gr.Blocks() as demo:
|
161 |
+
gr.HTML(TITLE)
|
162 |
+
gr.HTML(SUBTITLE)
|
163 |
with gr.Column():
|
164 |
chatbot_component.render()
|
165 |
with gr.Row():
|