Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -52,9 +52,6 @@ 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 |
-
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,31 +75,24 @@ 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 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
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(
|
@@ -123,27 +113,8 @@ model_choice_component = gr.Dropdown(
|
|
123 |
scale=2
|
124 |
)
|
125 |
|
126 |
-
# Nuevos dropdowns para personalizar la entrada
|
127 |
-
genre_component = gr.Dropdown(
|
128 |
-
choices=["History", "Poem", "Short Story", "Quote"],
|
129 |
-
label="Select Genre",
|
130 |
-
scale=2
|
131 |
-
)
|
132 |
-
|
133 |
-
language_component = gr.Dropdown(
|
134 |
-
choices=["English", "Spanish", "French"],
|
135 |
-
label="Select Language",
|
136 |
-
scale=2
|
137 |
-
)
|
138 |
-
|
139 |
-
mood_component = gr.Dropdown(
|
140 |
-
choices=["Happy", "Sad", "Romantic", "Horror", "Comical"],
|
141 |
-
label="Select Mood",
|
142 |
-
scale=2
|
143 |
-
)
|
144 |
-
|
145 |
user_inputs = [text_prompt_component, chatbot_component]
|
146 |
-
bot_inputs = [upload_button_component, model_choice_component, system_instruction_component, chatbot_component
|
147 |
|
148 |
# Definir la interfaz de usuario
|
149 |
with gr.Blocks() as demo:
|
@@ -162,11 +133,6 @@ with gr.Blocks() as demo:
|
|
162 |
with gr.Accordion("System Instruction", open=False): # Acorde贸n cerrado por defecto
|
163 |
system_instruction_component.render()
|
164 |
|
165 |
-
# Agregar los nuevos desplegables (dropdowns) para personalizaci贸n
|
166 |
-
genre_component.render()
|
167 |
-
language_component.render()
|
168 |
-
mood_component.render()
|
169 |
-
|
170 |
run_button_component.click(
|
171 |
fn=user,
|
172 |
inputs=user_inputs,
|
|
|
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 |
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 |
+
response = model.generate_content(text_prompt + image_prompt, stream=True, generation_config=generation_config)
|
88 |
+
|
89 |
+
chatbot[-1][1] = ""
|
90 |
+
for chunk in response:
|
91 |
+
for i in range(0, len(chunk.text), 10):
|
92 |
+
section = chunk.text[i:i + 10]
|
93 |
+
chatbot[-1][1] += section
|
94 |
+
time.sleep(0.01)
|
95 |
+
yield chatbot
|
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
|
|
113 |
scale=2
|
114 |
)
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
user_inputs = [text_prompt_component, chatbot_component]
|
117 |
+
bot_inputs = [upload_button_component, model_choice_component, system_instruction_component, chatbot_component]
|
118 |
|
119 |
# Definir la interfaz de usuario
|
120 |
with gr.Blocks() as demo:
|
|
|
133 |
with gr.Accordion("System Instruction", open=False): # Acorde贸n cerrado por defecto
|
134 |
system_instruction_component.render()
|
135 |
|
|
|
|
|
|
|
|
|
|
|
136 |
run_button_component.click(
|
137 |
fn=user,
|
138 |
inputs=user_inputs,
|