dreibh commited on
Commit
953f112
·
verified ·
1 Parent(s): 479e59a

Updated the documentation with instructions for running the application locally.

Browse files
Files changed (3) hide show
  1. README.md +19 -1
  2. app.py +7 -6
  3. requirements.txt +2 -1
README.md CHANGED
@@ -11,6 +11,24 @@ license: cc-by-4.0
11
  short_description: Fake ECG Generator
12
  ---
13
 
 
 
14
  Allows to generate ECGs. Based on the following paper:
15
 
16
- https://www.nature.com/articles/s41598-021-01295-2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  short_description: Fake ECG Generator
12
  ---
13
 
14
+ # Deepfake ECG Generator GUI
15
+
16
  Allows to generate ECGs. Based on the following paper:
17
 
18
+ https://www.nature.com/articles/s41598-021-01295-2
19
+
20
+ # Run locally
21
+
22
+ ## Prepare venv and install dependencies
23
+ ```bash
24
+ mkdir -p ~/python-environments/deepfake-ecg
25
+ python3 -m venv ~/python-environments/deepfake-ecg
26
+ . ~/python-environments/deepfake-ecg/bin/activate
27
+ pip install -r requirements.txt
28
+ ```
29
+
30
+ ## Run the application
31
+ ```bash
32
+ ./app.py
33
+ ```
34
+ Then, connect a web browser to http://127.0.0.1:7860/ to use the application
app.py CHANGED
@@ -1,6 +1,8 @@
 
 
 
1
  import io
2
  import gradio as gr
3
- #from transformers import pipeline
4
  from transformers import AutoModel
5
  import ecg_plot
6
  import matplotlib.pyplot as plt
@@ -11,17 +13,16 @@ model = AutoModel.from_pretrained("deepsynthbody/deepfake_ecg", trust_remote_cod
11
 
12
  def predict():
13
  prediction = (model(1)[0].t()/1000) # to micro volte
14
-
15
-
16
  lead_III = (prediction[1] - prediction[0]).unsqueeze(dim=0)
17
  lead_aVR = ((prediction[0] + prediction[1])*(-0.5)).unsqueeze(dim=0)
18
  lead_aVL = (prediction[0] - prediction[1]* 0.5).unsqueeze(dim=0)
19
  lead_aVF = (prediction[1] - prediction[0]* 0.5).unsqueeze(dim=0)
20
  all = torch.cat((prediction, lead_III, lead_aVR, lead_aVL, lead_aVF), dim=0)
21
  all_corrected = all[torch.tensor([0,1,8, 9, 10, 11, 2,3,4,5,6,7])]
22
-
23
  ecg_plot.plot(all_corrected, sample_rate = 500, title = 'ECG 12')
24
-
25
  #ecg_plot.show()
26
  buf = io.BytesIO()
27
  plt.savefig(buf, format="png")
@@ -33,4 +34,4 @@ gr.Interface(
33
  inputs=None,
34
  outputs="image",
35
  title="Generating Fake ECGs",
36
- ).launch()
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
  import io
5
  import gradio as gr
 
6
  from transformers import AutoModel
7
  import ecg_plot
8
  import matplotlib.pyplot as plt
 
13
 
14
  def predict():
15
  prediction = (model(1)[0].t()/1000) # to micro volte
16
+
 
17
  lead_III = (prediction[1] - prediction[0]).unsqueeze(dim=0)
18
  lead_aVR = ((prediction[0] + prediction[1])*(-0.5)).unsqueeze(dim=0)
19
  lead_aVL = (prediction[0] - prediction[1]* 0.5).unsqueeze(dim=0)
20
  lead_aVF = (prediction[1] - prediction[0]* 0.5).unsqueeze(dim=0)
21
  all = torch.cat((prediction, lead_III, lead_aVR, lead_aVL, lead_aVF), dim=0)
22
  all_corrected = all[torch.tensor([0,1,8, 9, 10, 11, 2,3,4,5,6,7])]
23
+
24
  ecg_plot.plot(all_corrected, sample_rate = 500, title = 'ECG 12')
25
+
26
  #ecg_plot.show()
27
  buf = io.BytesIO()
28
  plt.savefig(buf, format="png")
 
34
  inputs=None,
35
  outputs="image",
36
  title="Generating Fake ECGs",
37
+ ).launch()
requirements.txt CHANGED
@@ -1,5 +1,6 @@
 
1
  transformers
2
  torch
3
  ecg-plot
4
  matplotlib
5
- Pillow
 
1
+ gradio
2
  transformers
3
  torch
4
  ecg-plot
5
  matplotlib
6
+ Pillow