Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,12 @@
|
|
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,6 +69,11 @@ def bot(
|
|
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,11 +82,10 @@ def bot(
|
|
80 |
top_p=top_p
|
81 |
)
|
82 |
|
83 |
-
|
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 +
|
88 |
|
89 |
chatbot[-1][1] = ""
|
90 |
for chunk in response:
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import time
|
3 |
import uuid
|
4 |
from typing import List, Tuple, Optional, Dict, Union
|
|
|
5 |
import google.generativeai as genai
|
6 |
import gradio as gr
|
7 |
from PIL import Image
|
8 |
from dotenv import load_dotenv
|
9 |
+
from langdetect import detect # Agregar para la detecci贸n del idioma
|
10 |
|
11 |
# Cargar las variables de entorno desde el archivo .env
|
12 |
load_dotenv()
|
|
|
69 |
|
70 |
# Configurar la API con la clave
|
71 |
genai.configure(api_key=GOOGLE_API_KEY)
|
72 |
+
|
73 |
+
# Detectar el idioma del texto ingresado
|
74 |
+
text_prompt = [chatbot[-1][0]] if chatbot and chatbot[-1][0] and isinstance(chatbot[-1][0], str) else []
|
75 |
+
detected_language = detect(text_prompt[-1]) if text_prompt else 'en' # Detectar el idioma del texto
|
76 |
+
|
77 |
generation_config = genai.types.GenerationConfig(
|
78 |
temperature=temperature,
|
79 |
max_output_tokens=max_output_tokens,
|
|
|
82 |
top_p=top_p
|
83 |
)
|
84 |
|
85 |
+
# Crear el modelo con el idioma detectado
|
|
|
86 |
model_name = 'gemini-1.5-flash'
|
87 |
model = genai.GenerativeModel(model_name)
|
88 |
+
response = model.generate_content(text_prompt + [], stream=True, generation_config=generation_config, language=detected_language)
|
89 |
|
90 |
chatbot[-1][1] = ""
|
91 |
for chunk in response:
|