C2MV commited on
Commit
d474e7f
verified
1 Parent(s): 59156e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -1,26 +1,24 @@
1
  import os
2
  os.system('pip install curl_cffi tqdm bitsandbytes tiktoken g4f pinecone-client pandas datasets sentence-transformers')
3
 
4
- # Retrieve the Pinecone API key from the user
5
- PINECONE_API_KEY = "3a3e9022-381d-436e-84cb-ba93464d283e" # Use the key you set in the secrets
6
- PINECONE_ENVIRONMENT = "us-east-1" # Use the environment you set in the secrets
7
-
8
  # Setup and load your keys
9
  import os
10
  from g4f import ChatCompletion
 
11
  from pinecone import Pinecone
12
  import pandas as pd
13
  from datasets import Dataset
14
  from sentence_transformers import SentenceTransformer
15
  import gradio as gr
16
 
 
17
  #TEMA GRADIO
18
  import gradio as gr
19
 
20
  theme = gr.themes.Default(
21
- primary_hue="indigo",
22
- secondary_hue="indigo",
23
- neutral_hue=gr.themes.Color(c100="#384b8f", c200="#d7dbe5", c300="#1d1d20", c400="#1d1d20", c50="#657ed2", c500="#fcfcfc", c600="#3d3e52", c700="#383947", c800="#242429", c900="#29292e", c950="#292932"),
24
  ).set(
25
  background_fill_primary='*background_fill_secondary',
26
  border_color_accent_subdued='*border_color_accent',
@@ -71,6 +69,10 @@ theme = gr.themes.Default(
71
 
72
  model_name = "BAAI/bge-m3"
73
 
 
 
 
 
74
  # Initialize Pinecone with the API key
75
  pc = Pinecone(api_key=PINECONE_API_KEY)
76
 
@@ -90,6 +92,9 @@ def print_current_selection():
90
  # Establecer el nombre del 铆ndice autom谩ticamente
91
  INDEX_NAME = 'neonatos'
92
 
 
 
 
93
  def connect_to_pinecone(index_name):
94
  global INDEX_NAME
95
  try:
@@ -243,6 +248,7 @@ def chat_function(message, history):
243
  if filtered_links:
244
  full_response += filtered_links[0] #f".\n\nRespuesta:\n" + filtered_links[0]
245
 
 
246
  # Now handle the images based on the detected tags
247
  tags_to_images = {
248
  "rId101": "images/rId101.png",
@@ -291,6 +297,8 @@ def chat_function(message, history):
291
  "rId97": "images/rId97.png",
292
  }
293
 
 
 
294
  for tag in tags_detected:
295
  for key, path in tags_to_images.items():
296
  if key in tag and check_image_exists(path):
@@ -306,6 +314,7 @@ def update_image(image_url):
306
  else:
307
  return None
308
 
 
309
  images = [
310
  {"id": "rId101", "path": "images/rId101.png", "description": "馃搳 El c贸digo UBIGEO muestra que Lima (150101) tiene el mayor n煤mero de registros, seguido por Trujillo (130101) y San Juan de Miraflores (150133), destacando la concentraci贸n de atenci贸n m茅dica en estas zonas. Un gr谩fico de barras visualiza los 10 c贸digos UBIGEO m谩s frecuentes, facilitando la identificaci贸n de las 谩reas con mayor actividad en salud."},
311
  {"id": "rId105", "path": "images/rId105.png", "description": "馃彞 Los establecimientos de nivel 3 son los m谩s representados, con 652,948 registros, seguidos por los de nivel 4 (310,272) y nivel 2 (277,385)."},
@@ -353,6 +362,8 @@ images = [
353
  {"id": "rId97", "path": "images/rId97.png", "description": ""},
354
  ]
355
 
 
 
356
  # Gradio layout setup
357
  with gr.Blocks(theme=theme) as demo:
358
  with gr.Row():
 
1
  import os
2
  os.system('pip install curl_cffi tqdm bitsandbytes tiktoken g4f pinecone-client pandas datasets sentence-transformers')
3
 
 
 
 
 
4
  # Setup and load your keys
5
  import os
6
  from g4f import ChatCompletion
7
+ #from google.colab import userdata
8
  from pinecone import Pinecone
9
  import pandas as pd
10
  from datasets import Dataset
11
  from sentence_transformers import SentenceTransformer
12
  import gradio as gr
13
 
14
+
15
  #TEMA GRADIO
16
  import gradio as gr
17
 
18
  theme = gr.themes.Default(
19
+ primary_hue=gr.themes.Color(c100="#83a1c9", c200="#000000", c300="#a5b4fc", c400="#818cf8", c50="#ffffff", c500="#6366f1", c600="#4f46e5", c700="#4338ca", c800="#3730a3", c900="#312e81", c950="#2b2c5e"),
20
+ secondary_hue=gr.themes.Color(c100="#ffffff", c200="#9ab9d5", c300="#000000", c400="#000000", c50="#ffffff", c500="#000000", c600="#000000", c700="#000000", c800="#3730a3", c900="#312e81", c950="#2b2c5e"),
21
+ neutral_hue=gr.themes.Color(c100="#e0e7ff", c200="#c7d2fe", c300="#658fd2", c400="#ffffff", c50="#eef2ff", c500="#ffffff", c600="#191a2f", c700="#29357f", c800="#4463a2", c900="#545acf", c950="#1a1a1f"),
22
  ).set(
23
  background_fill_primary='*background_fill_secondary',
24
  border_color_accent_subdued='*border_color_accent',
 
69
 
70
  model_name = "BAAI/bge-m3"
71
 
72
+ # Retrieve the Pinecone API key from the user
73
+ PINECONE_API_KEY = "3a3e9022-381d-436e-84cb-ba93464d283e" # Use the key you set in the secrets
74
+ PINECONE_ENVIRONMENT = "us-east-1" # Use the environment you set in the secrets
75
+
76
  # Initialize Pinecone with the API key
77
  pc = Pinecone(api_key=PINECONE_API_KEY)
78
 
 
92
  # Establecer el nombre del 铆ndice autom谩ticamente
93
  INDEX_NAME = 'neonatos'
94
 
95
+ # Obtener la clave API de Pinecone
96
+ #PINECONE_API_KEY = userdata.get('PINECONE_API_KEY')
97
+
98
  def connect_to_pinecone(index_name):
99
  global INDEX_NAME
100
  try:
 
248
  if filtered_links:
249
  full_response += filtered_links[0] #f".\n\nRespuesta:\n" + filtered_links[0]
250
 
251
+
252
  # Now handle the images based on the detected tags
253
  tags_to_images = {
254
  "rId101": "images/rId101.png",
 
297
  "rId97": "images/rId97.png",
298
  }
299
 
300
+
301
+
302
  for tag in tags_detected:
303
  for key, path in tags_to_images.items():
304
  if key in tag and check_image_exists(path):
 
314
  else:
315
  return None
316
 
317
+
318
  images = [
319
  {"id": "rId101", "path": "images/rId101.png", "description": "馃搳 El c贸digo UBIGEO muestra que Lima (150101) tiene el mayor n煤mero de registros, seguido por Trujillo (130101) y San Juan de Miraflores (150133), destacando la concentraci贸n de atenci贸n m茅dica en estas zonas. Un gr谩fico de barras visualiza los 10 c贸digos UBIGEO m谩s frecuentes, facilitando la identificaci贸n de las 谩reas con mayor actividad en salud."},
320
  {"id": "rId105", "path": "images/rId105.png", "description": "馃彞 Los establecimientos de nivel 3 son los m谩s representados, con 652,948 registros, seguidos por los de nivel 4 (310,272) y nivel 2 (277,385)."},
 
362
  {"id": "rId97", "path": "images/rId97.png", "description": ""},
363
  ]
364
 
365
+
366
+
367
  # Gradio layout setup
368
  with gr.Blocks(theme=theme) as demo:
369
  with gr.Row():