SergioSCA commited on
Commit
efdd1f5
verified
1 Parent(s): cba4d16

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +131 -81
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 == "NLP" and task == "Clasificaci贸n de Texto":
12
- columns.extend(["texto", "etiqueta"])
13
- elif modality == "Audio" and task == "Clasificaci贸n de Audio":
14
- columns.extend(["archivo_audio", "etiqueta"])
15
- return ", ".join(columns)
16
-
17
- # Funci贸n para buscar datasets p煤blicos relevantes
18
- def search_datasets(modalities):
19
- # Simulaci贸n de b煤squeda de datasets en Hugging Face
20
- dataset_map = {
21
- "Visi贸n": ["coco", "imagenet"],
22
- "NLP": ["imdb", "glue"],
23
- "Audio": ["common_voice", "librispeech"]
24
- }
25
- results = []
26
- for modality in modalities:
27
- if modality in dataset_map:
28
- results.extend(dataset_map[modality])
29
- return "\n".join(results)
30
-
31
- # Funci贸n para procesar datasets seleccionados
32
- def process_datasets(dataset_urls):
33
- datasets = []
34
- for url in dataset_urls.split("\n"):
35
- if url.strip():
36
- try:
37
- dataset = load_dataset(url.strip())
38
- datasets.append(dataset)
39
- except Exception as e:
40
- return f"Error al cargar el dataset {url}: {str(e)}"
41
- combined_dataset = pd.concat([pd.DataFrame(ds) for ds in datasets], ignore_index=True)
42
- return combined_dataset.to_csv(index=False)
43
-
44
- # Interfaz de Usuario con Gradio
45
- with gr.Blocks(title="Dise帽ador de Redes Neuronales Multimodales") as demo:
46
- gr.Markdown("# Dise帽ador de Redes Neuronales Multimodales")
47
- gr.Markdown("Define tu red neuronal multimodal, genera datasets espec铆ficos y entrena modelos.")
48
-
49
- with gr.Row():
50
- modalities = gr.CheckboxGroup(
51
- ["Visi贸n", "NLP", "Audio"], label="Selecciona Modalidades"
52
- )
53
- tasks = gr.Dropdown(
54
- [
55
- "Detecci贸n de Objetos",
56
- "Clasificaci贸n de Texto",
57
- "Clasificaci贸n de Audio",
58
- ],
59
- multiselect=True,
60
- label="Selecciona Tareas",
61
- )
62
-
63
- with gr.Row():
64
- generate_csv_btn = gr.Button("Generar Esquema CSV")
65
- csv_output = gr.Textbox(label="Esquema CSV Generado")
66
-
67
- with gr.Row():
68
- search_datasets_btn = gr.Button("Buscar Datasets P煤blicos")
69
- datasets_output = gr.Textbox(label="Datasets Disponibles")
70
-
71
- with gr.Row():
72
- dataset_urls = gr.Textbox(lines=5, label="Introduce URLs de Datasets")
73
- process_datasets_btn = gr.Button("Procesar Datasets")
74
- processed_output = gr.File(label="Dataset Procesado")
75
-
76
- # Conexiones de botones a funciones
77
- generate_csv_btn.click(generate_csv, inputs=[modalities, tasks], outputs=csv_output)
78
- search_datasets_btn.click(search_datasets, inputs=[modalities], outputs=datasets_output)
79
- process_datasets_btn.click(process_datasets, inputs=[dataset_urls], outputs=processed_output)
80
-
81
- # Lanzar la aplicaci贸n
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()