import gradio as gr import plotly.graph_objects as go import pandas as pd # Datos para la línea cronológica data = pd.DataFrame([ {"start_year": 1959, "end_year": 1960, "enfoque": "ENFOQUE PSICOANALÍTICO"}, {"start_year": 1960, "end_year": 1970, "enfoque": "TEORÍAS SOCIOLÓGICAS Y ECOLÓGICAS"}, {"start_year": 1970, "end_year": 1980, "enfoque": "PRIMERAS APROXIMACIONES CRIMINOLÓGICAS"}, {"start_year": 1970, "end_year": 1980, "enfoque": "TEORÍAS FEMINISTAS Y SOCIOCULTURALES"}, {"start_year": 1980, "end_year": 2000, "enfoque": "TEORÍAS CRIMINOLÓGICAS"}, {"start_year": 2000, "end_year": 2024, "enfoque": "ENFOQUES MULTIDISCIPLINARES"} ]) # Colores para cada enfoque colors = { "ENFOQUE PSICOANALÍTICO": "#FF9999", "TEORÍAS SOCIOLÓGICAS Y ECOLÓGICAS": "#66B2FF", "PRIMERAS APROXIMACIONES CRIMINOLÓGICAS": "#99FF99", "TEORÍAS FEMINISTAS Y SOCIOCULTURALES": "#FFCC99", "TEORÍAS CRIMINOLÓGICAS": "#FF6666", "ENFOQUES MULTIDISCIPLINARES": "#CCCCFF" } # Función para crear la línea cronológica def create_plot(): fig = go.Figure() # Añadir los tramos de colores for _, row in data.iterrows(): fig.add_trace(go.Scatter( x=[row['start_year'], row['end_year']], y=[0.5, 0.5], mode='lines', line=dict(color=colors[row['enfoque']], width=15), name=row['enfoque'] )) # Añadir etiquetas de los enfoques for _, row in data.iterrows(): fig.add_annotation( x=(row['start_year'] + row['end_year']) / 2, y=0.55, text=row['enfoque'], showarrow=False, font=dict(size=10, color='black', family='Arial'), align='center' ) # Configurar los ejes fig.update_xaxes( title_text='Año', tickvals=list(range(1959, 2025, 5)), ticktext=list(range(1959, 2025, 5)), title_font=dict(size=14), tickangle=45 ) fig.update_yaxes(visible=False) # Añadir título y diseño fig.update_layout( title="Línea Cronológica de Investigaciones sobre Agresiones Sexuales Grupales (ASG)", title_font=dict(size=14), plot_bgcolor='#f7f7f7', xaxis_title='Año', showlegend=True, legend=dict(x=1, y=1, traceorder='normal') ) return fig.to_html(full_html=False) # Crear la interfaz de usuario con Gradio iface = gr.Interface( fn=create_plot, inputs=[], outputs=gr.HTML(label="Línea Cronológica"), live=True ) # Ejecutar la interfaz if __name__ == "__main__": iface.launch()