Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -52,6 +52,9 @@ def upload(files: Optional[List[str]], chatbot: CHAT_HISTORY) -> CHAT_HISTORY:
|
|
52 |
def user(text_prompt: str, chatbot: CHAT_HISTORY):
|
53 |
if text_prompt:
|
54 |
chatbot.append((text_prompt, None))
|
|
|
|
|
|
|
55 |
return "", chatbot
|
56 |
|
57 |
def bot(
|
@@ -75,24 +78,31 @@ def bot(
|
|
75 |
if not system_instruction:
|
76 |
system_instruction = "" # O puedes poner un valor predeterminado como "No system instruction provided."
|
77 |
|
|
|
78 |
text_prompt = [chatbot[-1][0]] if chatbot and chatbot[-1][0] and isinstance(chatbot[-1][0], str) else []
|
79 |
image_prompt = [preprocess_image(Image.open(file).convert('RGB')) for file in files] if files else []
|
80 |
-
|
81 |
model = genai.GenerativeModel(
|
82 |
model_name=model_choice,
|
83 |
generation_config=generation_config,
|
84 |
system_instruction=system_instruction # Usar el valor por defecto si est谩 vac铆o
|
85 |
)
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
# Componente para el acorde贸n que contiene el cuadro de texto para la instrucci贸n del sistema
|
98 |
system_instruction_component = gr.Textbox(
|
|
|
52 |
def user(text_prompt: str, chatbot: CHAT_HISTORY):
|
53 |
if text_prompt:
|
54 |
chatbot.append((text_prompt, None))
|
55 |
+
else:
|
56 |
+
# Si no hay texto en el prompt, solicitamos que se ingrese
|
57 |
+
chatbot.append(("Please provide a text prompt.", None))
|
58 |
return "", chatbot
|
59 |
|
60 |
def bot(
|
|
|
78 |
if not system_instruction:
|
79 |
system_instruction = "" # O puedes poner un valor predeterminado como "No system instruction provided."
|
80 |
|
81 |
+
# Extraer texto y prepararlo para el prompt
|
82 |
text_prompt = [chatbot[-1][0]] if chatbot and chatbot[-1][0] and isinstance(chatbot[-1][0], str) else []
|
83 |
image_prompt = [preprocess_image(Image.open(file).convert('RGB')) for file in files] if files else []
|
84 |
+
|
85 |
model = genai.GenerativeModel(
|
86 |
model_name=model_choice,
|
87 |
generation_config=generation_config,
|
88 |
system_instruction=system_instruction # Usar el valor por defecto si est谩 vac铆o
|
89 |
)
|
90 |
|
91 |
+
# Si hay texto en el prompt, generamos contenido
|
92 |
+
if text_prompt:
|
93 |
+
response = model.generate_content(text_prompt + image_prompt, stream=True, generation_config=generation_config)
|
94 |
+
|
95 |
+
chatbot[-1][1] = ""
|
96 |
+
for chunk in response:
|
97 |
+
for i in range(0, len(chunk.text), 10):
|
98 |
+
section = chunk.text[i:i + 10]
|
99 |
+
chatbot[-1][1] += section
|
100 |
+
time.sleep(0.01)
|
101 |
+
yield chatbot
|
102 |
+
else:
|
103 |
+
# Si no hay texto, solicitamos que se ingrese uno
|
104 |
+
chatbot.append(("Please provide a text prompt.", None))
|
105 |
+
yield chatbot
|
106 |
|
107 |
# Componente para el acorde贸n que contiene el cuadro de texto para la instrucci贸n del sistema
|
108 |
system_instruction_component = gr.Textbox(
|