tiffank1802 commited on
Commit
cf1e876
·
1 Parent(s): 2f48907

Fix Gradio Blocks context issue and matplotlib backend

Browse files
README.md CHANGED
@@ -3,8 +3,8 @@ title: Jumeaux Numériques Complets
3
  emoji: 🔄
4
  colorFrom: blue
5
  colorTo: green
6
- sdk: streamlit
7
- sdk_version: 1.28.0
8
  app_file: app.py
9
  pinned: false
10
  ---
 
3
  emoji: 🔄
4
  colorFrom: blue
5
  colorTo: green
6
+ sdk: gradio
7
+ sdk_version: "4.44.1"
8
  app_file: app.py
9
  pinned: false
10
  ---
__pycache__/app.cpython-312.pyc ADDED
Binary file (15.2 kB). View file
 
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import gradio as gr
2
  import numpy as np
 
 
3
  import matplotlib.pyplot as plt
4
 
5
  def create_introduction_plot(fidelity, noise, gain):
@@ -162,9 +164,9 @@ with gr.Blocks(title="Jumeaux Numériques") as demo:
162
  gain = gr.Slider(0.1, 2.0, 1.0, label="Gain de contrôle")
163
  plot_intro = gr.Plot()
164
 
165
- fidelity.change(lambda f, n, g: create_introduction_plot(f, n, g), [fidelity, noise, gain], plot_intro)
166
- noise.change(lambda f, n, g: create_introduction_plot(f, n, g), [fidelity, noise, gain], plot_intro)
167
- gain.change(lambda f, n, g: create_introduction_plot(f, n, g), [fidelity, noise, gain], plot_intro)
168
  plot_intro.value = create_introduction_plot(0.7, 0.1, 1.0)
169
 
170
  # Kalman Filter
@@ -177,7 +179,6 @@ with gr.Blocks(title="Jumeaux Numériques") as demo:
177
  r_param = gr.Slider(1e-6, 0.1, 0.05, label="Bruit mesure R")
178
  plot_kalman = gr.Plot()
179
  run_kalman = gr.Button("🚀 Lancer simulation")
180
- run_kalman.click(create_kalman_plot, [a_param, dt_param, q_param, r_param], plot_kalman)
181
 
182
  # PID Control
183
  with gr.Tab("🎯 Contrôle PID"):
@@ -190,7 +191,6 @@ with gr.Blocks(title="Jumeaux Numériques") as demo:
190
  ref = gr.Slider(-5.0, 5.0, 1.0, label="Consigne")
191
  plot_pid = gr.Plot()
192
  run_pid = gr.Button("🎯 Lancer contrôle PID")
193
- run_pid.click(create_pid_plot, [system_type, Kp, Ki, Kd, ref], plot_pid)
194
 
195
  # Exercises
196
  with gr.Tab("📊 Exercices"):
@@ -205,6 +205,10 @@ with gr.Blocks(title="Jumeaux Numériques") as demo:
205
  param2 = gr.Slider(0.01, 1.0, 0.1, label="Paramètre 2")
206
  exercise_plot = gr.Plot()
207
  run_exercise = gr.Button("📚 Résoudre l'exercice")
208
- run_exercise.click(create_exercise_plot, [exercise_choice, param1, param2], exercise_plot)
 
 
 
 
209
 
210
  demo.launch()
 
1
  import gradio as gr
2
  import numpy as np
3
+ import matplotlib
4
+ matplotlib.use('Agg')
5
  import matplotlib.pyplot as plt
6
 
7
  def create_introduction_plot(fidelity, noise, gain):
 
164
  gain = gr.Slider(0.1, 2.0, 1.0, label="Gain de contrôle")
165
  plot_intro = gr.Plot()
166
 
167
+ fidelity.change(create_introduction_plot, [fidelity, noise, gain], plot_intro)
168
+ noise.change(create_introduction_plot, [fidelity, noise, gain], plot_intro)
169
+ gain.change(create_introduction_plot, [fidelity, noise, gain], plot_intro)
170
  plot_intro.value = create_introduction_plot(0.7, 0.1, 1.0)
171
 
172
  # Kalman Filter
 
179
  r_param = gr.Slider(1e-6, 0.1, 0.05, label="Bruit mesure R")
180
  plot_kalman = gr.Plot()
181
  run_kalman = gr.Button("🚀 Lancer simulation")
 
182
 
183
  # PID Control
184
  with gr.Tab("🎯 Contrôle PID"):
 
191
  ref = gr.Slider(-5.0, 5.0, 1.0, label="Consigne")
192
  plot_pid = gr.Plot()
193
  run_pid = gr.Button("🎯 Lancer contrôle PID")
 
194
 
195
  # Exercises
196
  with gr.Tab("📊 Exercices"):
 
205
  param2 = gr.Slider(0.01, 1.0, 0.1, label="Paramètre 2")
206
  exercise_plot = gr.Plot()
207
  run_exercise = gr.Button("📚 Résoudre l'exercice")
208
+
209
+ # Event handlers
210
+ run_kalman.click(create_kalman_plot, [a_param, dt_param, q_param, r_param], plot_kalman)
211
+ run_pid.click(create_pid_plot, [system_type, Kp, Ki, Kd, ref], plot_pid)
212
+ run_exercise.click(create_exercise_plot, [exercise_choice, param1, param2], exercise_plot)
213
 
214
  demo.launch()
src/exercises/__init__.py CHANGED
@@ -1,5 +1,7 @@
1
  import streamlit as st
2
  import numpy as np
 
 
3
  import matplotlib.pyplot as plt
4
  import pandas as pd
5
  from scipy import linalg
 
1
  import streamlit as st
2
  import numpy as np
3
+ import matplotlib
4
+ matplotlib.use('Agg')
5
  import matplotlib.pyplot as plt
6
  import pandas as pd
7
  from scipy import linalg