Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ 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
|
|
@@ -58,6 +59,12 @@ def user(text_prompt: str, chatbot: CHAT_HISTORY):
|
|
| 58 |
chatbot.append((text_prompt, None))
|
| 59 |
return "", chatbot
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
def bot(
|
| 62 |
files: Optional[List[str]],
|
| 63 |
temperature: float,
|
|
@@ -72,12 +79,19 @@ 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,
|
| 78 |
stop_sequences=preprocess_stop_sequences(stop_sequences=stop_sequences),
|
| 79 |
top_k=top_k,
|
| 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 []
|
|
|
|
| 5 |
import time
|
| 6 |
import uuid
|
| 7 |
from typing import List, Tuple, Optional, Dict, Union
|
| 8 |
+
from langdetect import detect
|
| 9 |
|
| 10 |
import google.generativeai as genai
|
| 11 |
import gradio as gr
|
|
|
|
| 59 |
chatbot.append((text_prompt, None))
|
| 60 |
return "", chatbot
|
| 61 |
|
| 62 |
+
def detect_language(text: str) -> str:
|
| 63 |
+
try:
|
| 64 |
+
return detect(text)
|
| 65 |
+
except:
|
| 66 |
+
return "en" # En caso de no poder detectar el idioma, se usa el ingl茅s por defecto
|
| 67 |
+
|
| 68 |
def bot(
|
| 69 |
files: Optional[List[str]],
|
| 70 |
temperature: float,
|
|
|
|
| 79 |
|
| 80 |
# Configurar la API con la clave
|
| 81 |
genai.configure(api_key=GOOGLE_API_KEY)
|
| 82 |
+
|
| 83 |
+
# Detectar el idioma del 煤ltimo mensaje del usuario
|
| 84 |
+
last_user_message = chatbot[-1][0] if chatbot and chatbot[-1][0] else ""
|
| 85 |
+
detected_language = detect_language(last_user_message)
|
| 86 |
+
|
| 87 |
+
# Configurar la generaci贸n para que utilice el idioma detectado
|
| 88 |
generation_config = genai.types.GenerationConfig(
|
| 89 |
temperature=temperature,
|
| 90 |
max_output_tokens=max_output_tokens,
|
| 91 |
stop_sequences=preprocess_stop_sequences(stop_sequences=stop_sequences),
|
| 92 |
top_k=top_k,
|
| 93 |
+
top_p=top_p,
|
| 94 |
+
language=detected_language # Usar el idioma detectado
|
| 95 |
)
|
| 96 |
|
| 97 |
text_prompt = [chatbot[-1][0]] if chatbot and chatbot[-1][0] and isinstance(chatbot[-1][0], str) else []
|