Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -72,8 +72,7 @@ def bot(
|
|
72 |
stop_sequences: str,
|
73 |
top_k: int,
|
74 |
top_p: float,
|
75 |
-
chatbot: CHAT_HISTORY
|
76 |
-
selected_model: str
|
77 |
):
|
78 |
if not GOOGLE_API_KEY:
|
79 |
raise ValueError("GOOGLE_API_KEY is not set.")
|
@@ -90,9 +89,8 @@ def bot(
|
|
90 |
|
91 |
text_prompt = [chatbot[-1][0]] if chatbot and chatbot[-1][0] and isinstance(chatbot[-1][0], str) else []
|
92 |
image_prompt = [preprocess_image(Image.open(file).convert('RGB')) for file in files] if files else []
|
93 |
-
|
94 |
-
|
95 |
-
model = genai.GenerativeModel(selected_model)
|
96 |
response = model.generate_content(text_prompt + image_prompt, stream=True, generation_config=generation_config)
|
97 |
|
98 |
chatbot[-1][1] = ""
|
@@ -103,7 +101,6 @@ def bot(
|
|
103 |
time.sleep(0.01)
|
104 |
yield chatbot
|
105 |
|
106 |
-
# Componentes de la interfaz
|
107 |
chatbot_component = gr.Chatbot(
|
108 |
label='Gemini',
|
109 |
bubble_full_width=False,
|
@@ -152,24 +149,11 @@ top_p_component = gr.Slider(
|
|
152 |
label="Top-P",
|
153 |
)
|
154 |
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
'gemini-1.5-flash-8b', # High volume, lower intelligence tasks
|
160 |
-
'gemini-1.5-pro', # Complex reasoning tasks
|
161 |
-
'gemini-exp-1114' # Quality improvements
|
162 |
-
],
|
163 |
-
value='gemini-1.5-flash', # Valor por defecto
|
164 |
-
label="Select Gemini Model",
|
165 |
-
interactive=True
|
166 |
-
)
|
167 |
-
|
168 |
-
# Funci贸n para actualizar el modelo
|
169 |
-
def update_gemini_model(selected_model):
|
170 |
-
return selected_model
|
171 |
|
172 |
-
# Inputs para la funci贸n 'bot'
|
173 |
bot_inputs = [
|
174 |
upload_button_component,
|
175 |
temperature_component,
|
@@ -177,11 +161,9 @@ bot_inputs = [
|
|
177 |
stop_sequences_component,
|
178 |
top_k_component,
|
179 |
top_p_component,
|
180 |
-
chatbot_component
|
181 |
-
gemini_model_component
|
182 |
]
|
183 |
|
184 |
-
# Crear la interfaz Gradio
|
185 |
with gr.Blocks() as demo:
|
186 |
gr.HTML(TITLE)
|
187 |
gr.HTML(SUBTITLE)
|
@@ -200,27 +182,24 @@ with gr.Blocks() as demo:
|
|
200 |
top_k_component.render()
|
201 |
top_p_component.render()
|
202 |
|
203 |
-
# Ejecutar cuando se presiona el bot贸n de ejecuci贸n
|
204 |
run_button_component.click(
|
205 |
fn=user,
|
206 |
-
inputs=
|
207 |
outputs=[text_prompt_component, chatbot_component],
|
208 |
queue=False
|
209 |
).then(
|
210 |
fn=bot, inputs=bot_inputs, outputs=[chatbot_component],
|
211 |
)
|
212 |
|
213 |
-
# Acci贸n cuando se env铆a un texto
|
214 |
text_prompt_component.submit(
|
215 |
fn=user,
|
216 |
-
inputs=
|
217 |
outputs=[text_prompt_component, chatbot_component],
|
218 |
queue=False
|
219 |
).then(
|
220 |
fn=bot, inputs=bot_inputs, outputs=[chatbot_component],
|
221 |
)
|
222 |
|
223 |
-
# Acci贸n cuando se suben im谩genes
|
224 |
upload_button_component.upload(
|
225 |
fn=upload,
|
226 |
inputs=[upload_button_component, chatbot_component],
|
|
|
72 |
stop_sequences: str,
|
73 |
top_k: int,
|
74 |
top_p: float,
|
75 |
+
chatbot: CHAT_HISTORY
|
|
|
76 |
):
|
77 |
if not GOOGLE_API_KEY:
|
78 |
raise ValueError("GOOGLE_API_KEY is not set.")
|
|
|
89 |
|
90 |
text_prompt = [chatbot[-1][0]] if chatbot and chatbot[-1][0] and isinstance(chatbot[-1][0], str) else []
|
91 |
image_prompt = [preprocess_image(Image.open(file).convert('RGB')) for file in files] if files else []
|
92 |
+
model_name = 'gemini-pro-vision' if files else 'gemini-pro'
|
93 |
+
model = genai.GenerativeModel(model_name)
|
|
|
94 |
response = model.generate_content(text_prompt + image_prompt, stream=True, generation_config=generation_config)
|
95 |
|
96 |
chatbot[-1][1] = ""
|
|
|
101 |
time.sleep(0.01)
|
102 |
yield chatbot
|
103 |
|
|
|
104 |
chatbot_component = gr.Chatbot(
|
105 |
label='Gemini',
|
106 |
bubble_full_width=False,
|
|
|
149 |
label="Top-P",
|
150 |
)
|
151 |
|
152 |
+
user_inputs = [
|
153 |
+
text_prompt_component,
|
154 |
+
chatbot_component
|
155 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
|
|
|
157 |
bot_inputs = [
|
158 |
upload_button_component,
|
159 |
temperature_component,
|
|
|
161 |
stop_sequences_component,
|
162 |
top_k_component,
|
163 |
top_p_component,
|
164 |
+
chatbot_component
|
|
|
165 |
]
|
166 |
|
|
|
167 |
with gr.Blocks() as demo:
|
168 |
gr.HTML(TITLE)
|
169 |
gr.HTML(SUBTITLE)
|
|
|
182 |
top_k_component.render()
|
183 |
top_p_component.render()
|
184 |
|
|
|
185 |
run_button_component.click(
|
186 |
fn=user,
|
187 |
+
inputs=user_inputs,
|
188 |
outputs=[text_prompt_component, chatbot_component],
|
189 |
queue=False
|
190 |
).then(
|
191 |
fn=bot, inputs=bot_inputs, outputs=[chatbot_component],
|
192 |
)
|
193 |
|
|
|
194 |
text_prompt_component.submit(
|
195 |
fn=user,
|
196 |
+
inputs=user_inputs,
|
197 |
outputs=[text_prompt_component, chatbot_component],
|
198 |
queue=False
|
199 |
).then(
|
200 |
fn=bot, inputs=bot_inputs, outputs=[chatbot_component],
|
201 |
)
|
202 |
|
|
|
203 |
upload_button_component.upload(
|
204 |
fn=upload,
|
205 |
inputs=[upload_button_component, chatbot_component],
|