Update app.py
Browse files
app.py
CHANGED
@@ -1,82 +1,132 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from datasets import load_dataset
|
3 |
-
import pandas as pd
|
4 |
-
|
5 |
-
# Funci贸n para generar el esquema CSV basado en las selecciones del usuario
|
6 |
-
def generate_csv(modalities, tasks):
|
7 |
-
columns = []
|
8 |
-
for modality, task in zip(modalities, tasks):
|
9 |
-
if modality == "Visi贸n" and task == "Detecci贸n de Objetos":
|
10 |
-
columns.extend(["imagen", "etiqueta", "coordenadas_bbox"])
|
11 |
-
elif modality == "
|
12 |
-
columns.extend(["
|
13 |
-
elif modality == "
|
14 |
-
columns.extend(["
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
"
|
22 |
-
|
23 |
-
"
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
demo.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from datasets import load_dataset
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
# Funci贸n para generar el esquema CSV basado en las selecciones del usuario
|
6 |
+
def generate_csv(modalities, tasks):
|
7 |
+
columns = []
|
8 |
+
for modality, task in zip(modalities, tasks):
|
9 |
+
if modality == "Visi贸n" and task == "Detecci贸n de Objetos":
|
10 |
+
columns.extend(["imagen", "etiqueta", "coordenadas_bbox"])
|
11 |
+
elif modality == "Visi贸n" and task == "Segmentaci贸n Sem谩ntica":
|
12 |
+
columns.extend(["imagen", "m谩scara"])
|
13 |
+
elif modality == "Visi贸n" and task == "Clasificaci贸n de Im谩genes":
|
14 |
+
columns.extend(["imagen", "etiqueta"])
|
15 |
+
elif modality == "Visi贸n" and task == "Reconocimiento Facial":
|
16 |
+
columns.extend(["imagen", "identidad"])
|
17 |
+
elif modality == "NLP" and task == "Clasificaci贸n de Texto":
|
18 |
+
columns.extend(["texto", "etiqueta"])
|
19 |
+
elif modality == "NLP" and task == "Generaci贸n de Texto":
|
20 |
+
columns.extend(["entrada", "salida"])
|
21 |
+
elif modality == "NLP" and task == "Traducci贸n Autom谩tica":
|
22 |
+
columns.extend(["texto_original", "traducci贸n"])
|
23 |
+
elif modality == "NLP" and task == "An谩lisis de Sentimientos":
|
24 |
+
columns.extend(["texto", "sentimiento"])
|
25 |
+
elif modality == "Audio" and task == "Clasificaci贸n de Audio":
|
26 |
+
columns.extend(["archivo_audio", "etiqueta"])
|
27 |
+
elif modality == "Audio" and task == "Transcripci贸n de Voz":
|
28 |
+
columns.extend(["archivo_audio", "texto"])
|
29 |
+
elif modality == "Audio" and task == "Separaci贸n de Fuentes":
|
30 |
+
columns.extend(["archivo_audio", "fuente_separada"])
|
31 |
+
elif modality == "Audio" and task == "S铆ntesis de Voz":
|
32 |
+
columns.extend(["texto", "archivo_audio_generado"])
|
33 |
+
return ", ".join(columns)
|
34 |
+
|
35 |
+
# Funci贸n para buscar datasets p煤blicos relevantes
|
36 |
+
def search_datasets(modalities):
|
37 |
+
# Simulaci贸n de b煤squeda de datasets en Hugging Face
|
38 |
+
dataset_map = {
|
39 |
+
"Visi贸n": ["coco", "imagenet", "openimages", "cityscapes"],
|
40 |
+
"NLP": ["imdb", "glue", "wmt14", "sentiment140"],
|
41 |
+
"Audio": ["common_voice", "librispeech", "fma", "musdb18"]
|
42 |
+
}
|
43 |
+
results = []
|
44 |
+
for modality in modalities:
|
45 |
+
if modality in dataset_map:
|
46 |
+
results.extend(dataset_map[modality])
|
47 |
+
return "\n".join(results)
|
48 |
+
|
49 |
+
# Funci贸n para seleccionar datasets y agregarlos al campo de URLs
|
50 |
+
def select_datasets(selected_datasets, current_urls):
|
51 |
+
selected_datasets = selected_datasets.split("\n")
|
52 |
+
current_urls = current_urls.split("\n") if current_urls else []
|
53 |
+
updated_urls = list(set(current_urls + selected_datasets))
|
54 |
+
return "\n".join(updated_urls)
|
55 |
+
|
56 |
+
# Funci贸n para procesar datasets seleccionados
|
57 |
+
def process_datasets(dataset_urls):
|
58 |
+
datasets = []
|
59 |
+
for url in dataset_urls.split("\n"):
|
60 |
+
if url.strip():
|
61 |
+
try:
|
62 |
+
dataset = load_dataset(url.strip())
|
63 |
+
datasets.append(pd.DataFrame(dataset["train"]))
|
64 |
+
except Exception as e:
|
65 |
+
return f"Error al cargar el dataset {url}: {str(e)}"
|
66 |
+
combined_dataset = pd.concat(datasets, ignore_index=True)
|
67 |
+
return combined_dataset.to_csv(index=False)
|
68 |
+
|
69 |
+
# Interfaz de Usuario con Gradio
|
70 |
+
with gr.Blocks(title="Dise帽ador de Redes Neuronales Multimodales") as demo:
|
71 |
+
gr.Markdown("# Dise帽ador de Redes Neuronales Multimodales")
|
72 |
+
gr.Markdown("Define tu red neuronal multimodal, genera datasets espec铆ficos y entrena modelos.")
|
73 |
+
|
74 |
+
with gr.Row():
|
75 |
+
modalities = gr.CheckboxGroup(
|
76 |
+
["Visi贸n", "NLP", "Audio"], label="Selecciona Modalidades"
|
77 |
+
)
|
78 |
+
|
79 |
+
with gr.Row():
|
80 |
+
vision_tasks = gr.CheckboxGroup(
|
81 |
+
["Detecci贸n de Objetos", "Segmentaci贸n Sem谩ntica", "Clasificaci贸n de Im谩genes", "Reconocimiento Facial"],
|
82 |
+
label="Tareas para Visi贸n",
|
83 |
+
visible=False
|
84 |
+
)
|
85 |
+
nlp_tasks = gr.CheckboxGroup(
|
86 |
+
["Clasificaci贸n de Texto", "Generaci贸n de Texto", "Traducci贸n Autom谩tica", "An谩lisis de Sentimientos"],
|
87 |
+
label="Tareas para NLP",
|
88 |
+
visible=False
|
89 |
+
)
|
90 |
+
audio_tasks = gr.CheckboxGroup(
|
91 |
+
["Clasificaci贸n de Audio", "Transcripci贸n de Voz", "Separaci贸n de Fuentes", "S铆ntesis de Voz"],
|
92 |
+
label="Tareas para Audio",
|
93 |
+
visible=False
|
94 |
+
)
|
95 |
+
|
96 |
+
def update_task_visibility(modalities):
|
97 |
+
return [
|
98 |
+
gr.update(visible="Visi贸n" in modalities),
|
99 |
+
gr.update(visible="NLP" in modalities),
|
100 |
+
gr.update(visible="Audio" in modalities)
|
101 |
+
]
|
102 |
+
|
103 |
+
modalities.change(update_task_visibility, inputs=[modalities], outputs=[vision_tasks, nlp_tasks, audio_tasks])
|
104 |
+
|
105 |
+
with gr.Row():
|
106 |
+
generate_csv_btn = gr.Button("Generar Esquema CSV")
|
107 |
+
csv_output = gr.Textbox(label="Esquema CSV Generado")
|
108 |
+
|
109 |
+
with gr.Row():
|
110 |
+
search_datasets_btn = gr.Button("Buscar Datasets P煤blicos")
|
111 |
+
datasets_output = gr.Textbox(label="Datasets Disponibles", lines=5)
|
112 |
+
|
113 |
+
with gr.Row():
|
114 |
+
select_datasets_btn = gr.Button("Seleccionar Datasets")
|
115 |
+
dataset_urls = gr.Textbox(label="Introduce URLs de Datasets", lines=5)
|
116 |
+
|
117 |
+
with gr.Row():
|
118 |
+
process_datasets_btn = gr.Button("Procesar Datasets")
|
119 |
+
processed_output = gr.File(label="Dataset Procesado")
|
120 |
+
|
121 |
+
# Conexiones de botones a funciones
|
122 |
+
generate_csv_btn.click(
|
123 |
+
generate_csv,
|
124 |
+
inputs=[modalities, vision_tasks] + [modalities, nlp_tasks] + [modalities, audio_tasks],
|
125 |
+
outputs=csv_output
|
126 |
+
)
|
127 |
+
search_datasets_btn.click(search_datasets, inputs=[modalities], outputs=datasets_output)
|
128 |
+
select_datasets_btn.click(select_datasets, inputs=[datasets_output, dataset_urls], outputs=dataset_urls)
|
129 |
+
process_datasets_btn.click(process_datasets, inputs=[dataset_urls], outputs=processed_output)
|
130 |
+
|
131 |
+
# Lanzar la aplicaci贸n
|
132 |
demo.launch()
|