Quant0 commited on
Commit
ea71fb1
路
verified 路
1 Parent(s): d727c5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -2
app.py CHANGED
@@ -50,6 +50,31 @@ def exportar_a_excel(option_type, ticker_input, expiration_date, size_of_the_win
50
  return None, f"Error al exportar: {e}"
51
 
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  # Configuraci贸n de Gradio
54
  # --- Valores por defecto para inicializar la tabla ---
55
  initial_df_put = generar_tabla("put", "MSTR", None, 8)
@@ -84,10 +109,11 @@ with gr.Blocks(title="An谩lisis de Opciones") as demo:
84
  inputs=[ticker_input, expiration_date, size_of_the_window],
85
  outputs=[output_df_put, output_df_call]
86
  )
 
87
 
88
  btn_descargar.click(
89
- fn=exportar_a_excel,
90
- inputs=[option_type, ticker_input, expiration_date, size_of_the_window],
91
  outputs=[output_file, output_msg]
92
  )
93
 
 
50
  return None, f"Error al exportar: {e}"
51
 
52
 
53
+
54
+
55
+
56
+
57
+ def exportar_a_excel_con_hojas(df_puts, df_calls, ticker):
58
+ nombre_archivo = f"{ticker}_opciones.xlsx"
59
+ try:
60
+ with pd.ExcelWriter(nombre_archivo) as writer:
61
+ # Escribe el DataFrame de 'puts' en la primera hoja
62
+ if not df_puts.empty:
63
+ df_puts.to_excel(writer, sheet_name='Puts', index=False)
64
+
65
+ # Escribe el DataFrame de 'calls' en la segunda hoja
66
+ if not df_calls.empty:
67
+ df_calls.to_excel(writer, sheet_name='Calls', index=False)
68
+
69
+ return nombre_archivo, "Archivo Excel generado con 茅xito."
70
+ except Exception as e:
71
+ return None, f"Error al exportar: {e}"
72
+
73
+
74
+
75
+
76
+
77
+
78
  # Configuraci贸n de Gradio
79
  # --- Valores por defecto para inicializar la tabla ---
80
  initial_df_put = generar_tabla("put", "MSTR", None, 8)
 
109
  inputs=[ticker_input, expiration_date, size_of_the_window],
110
  outputs=[output_df_put, output_df_call]
111
  )
112
+ df_puts, df_calls = generar_todo(ticker_input, expiration_date, size_of_the_window)
113
 
114
  btn_descargar.click(
115
+ fn=exportar_a_excel_con_hojas,
116
+ inputs=[df_puts,df_calls, ticker_input],
117
  outputs=[output_file, output_msg]
118
  )
119