cryptocalypse commited on
Commit
3973fbd
verified
1 Parent(s): 1f5a26b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -3
app.py CHANGED
@@ -4,6 +4,58 @@ from huggingface_hub import InferenceClient
4
  import csv
5
  import json
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  def buscar_en_csv_y_generar_json(archivo_csv, valor_busqueda):
8
  resultados = []
9
 
@@ -65,7 +117,7 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
65
  css = "#component-2 {height: 350px}"
66
  def search(term):
67
 
68
- return buscar_en_csv_y_generar_json("proyectos_empresas.csv", term)
69
 
70
  with gr.Blocks(title="SPAIN WIND ENERGY LOBBY") as app:
71
  #with gr.Blocks(theme='gradio/soft') as demo:
@@ -88,7 +140,15 @@ with gr.Blocks(title="SPAIN WIND ENERGY LOBBY") as app:
88
  ],
89
  )
90
  """
91
-
 
 
 
 
 
 
 
 
92
  with gr.Row():
93
  to_convert = gr.Textbox(value="Forestalia",label="Search",scale=4)
94
  search_els = gr.Button("Search",scale=1)
@@ -105,4 +165,4 @@ with gr.Blocks(title="SPAIN WIND ENERGY LOBBY") as app:
105
 
106
 
107
  if __name__ == "__main__":
108
- app.launch()
 
4
  import csv
5
  import json
6
 
7
+ import matplotlib.pyplot as plt
8
+ import tempfile
9
+
10
+ # Par谩metros generales
11
+ r = 0.3 # Tasa de crecimiento
12
+ K = 1000 # Capacidad de carga
13
+ T = 20 # Tiempo total de simulaci贸n
14
+
15
+ # Funci贸n log铆stica
16
+ def logistic_growth(N, r, K):
17
+ return r * N * (1 - N / K)
18
+
19
+ # Funci贸n para simular el crecimiento
20
+ def simulate_population(t_values, initial_population, num_simulations):
21
+ population = np.zeros((len(t_values), num_simulations))
22
+ population[0] = initial_population
23
+ for t in range(1, len(t_values)):
24
+ for sim in range(num_simulations):
25
+ population[t, sim] = population[t-1, sim] + logistic_growth(population[t-1, sim], r, K)
26
+ return population
27
+
28
+ # Funci贸n para la interfaz de Gradio
29
+ def app(num_simulations, initial_population):
30
+ num_simulations = int(num_simulations)
31
+ initial_population = int(initial_population)
32
+
33
+ t_values = np.linspace(0, T, 100)
34
+ results = simulate_population(t_values, initial_population, num_simulations)
35
+
36
+ # Configuraci贸n de la visualizaci贸n
37
+ fig, axes = plt.subplots(nrows=num_simulations, ncols=1, figsize=(10, 8), sharex=True)
38
+
39
+ if num_simulations == 1:
40
+ axes = [axes]
41
+
42
+ for i, ax in enumerate(axes):
43
+ ax.plot(t_values, results[:, i], label=f'Simulaci贸n {i+1}', alpha=0.7)
44
+ ax.set_title(f'Simulaci贸n {i+1}')
45
+ ax.set_xlabel('Tiempo')
46
+ ax.set_ylabel('Poblaci贸n')
47
+ ax.legend()
48
+ ax.grid(True)
49
+ ax.set_ylim(0, 1200) # Ajustar l铆mites del eje y si es necesario
50
+
51
+ # Guardar la 煤ltima figura en un archivo temporal
52
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
53
+ temp_file.close()
54
+ fig.savefig(temp_file.name)
55
+ plt.close(fig)
56
+
57
+ return [temp_file.name, results.tolist()] # Devolver el nombre del archivo temporal y los resultados como lista
58
+
59
  def buscar_en_csv_y_generar_json(archivo_csv, valor_busqueda):
60
  resultados = []
61
 
 
117
  css = "#component-2 {height: 350px}"
118
  def search(term):
119
 
120
+ return buscar_en_csv_y_generar_json("proyectos_empresas_full.csv", term)
121
 
122
  with gr.Blocks(title="SPAIN WIND ENERGY LOBBY") as app:
123
  #with gr.Blocks(theme='gradio/soft') as demo:
 
140
  ],
141
  )
142
  """
143
+ with gr.Row():
144
+ gr.Interface(
145
+ fn=app,
146
+ inputs=["number", "number"],
147
+ outputs=["image", "json"], # Output de tipo imagen y json (para la lista de plots)
148
+ title="Simulaci贸n de crecimiento poblacional con bifurcaci贸n",
149
+ description="Esta aplicaci贸n simula el crecimiento poblacional de una especie con bifurcaciones seg煤n el modelo log铆stico. Ajusta el n煤mero de bifurcaciones y la poblaci贸n inicial para explorar diferentes escenarios."
150
+ )
151
+
152
  with gr.Row():
153
  to_convert = gr.Textbox(value="Forestalia",label="Search",scale=4)
154
  search_els = gr.Button("Search",scale=1)
 
165
 
166
 
167
  if __name__ == "__main__":
168
+ app.launch()