halil21 commited on
Commit
e830de4
·
verified ·
1 Parent(s): f899ab7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -17
app.py CHANGED
@@ -1,12 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
- """Untitled14.ipynb
3
-
4
- Automatically generated by Colab.
5
-
6
- Original file is located at
7
- https://colab.research.google.com/drive/1iYWQPQr4OVakQQHRAlYVFLDwdJ-933Tv
8
- """
9
-
10
  with open("app.py", "w") as f:
11
  f.write("""
12
  import torch
@@ -45,9 +36,27 @@ numeric_features = ['pvc_percent', 'PVCQRS', 'EF', 'Age', 'PVC_Prematurity_index
45
  'mean_HR', 'symptom_duration', 'QTc_sinus', 'PVCCI_dispersion',
46
  'CI_variability', 'PVC_Peak_QRS_duration', 'PVCCI', 'PVC_Compansatory_interval']
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  # Model ve scaler'ı yükleme
49
- model_path = "/content/tabtransformer_model.pth"
50
- scaler_path = "/content/trans_scaler.pkl"
51
 
52
  # Model tanımı
53
  input_dim = len(categorical_features) + len(numeric_features) # Toplam giriş boyutu
@@ -81,17 +90,19 @@ def predict(*inputs):
81
  logits = model(tensor_data)
82
  probabilities = F.softmax(logits, dim=1).numpy()
83
 
84
- return {"Response Probability": probabilities[0][0], "Non-response Probability": probabilities[0][1]}
 
 
 
85
 
86
  # Gradio arayüzü
87
  inputs = (
88
  [gr.Dropdown(choices=['Yes', 'No'], label=feature) for feature in categorical_features] +
89
- [gr.Number(label=feature) for feature in numeric_features]
90
  )
91
  outputs = gr.Label(label="Prediction")
92
  interface = gr.Interface(fn=predict, inputs=inputs, outputs=outputs, title="TabTransformer Prediction")
93
 
94
- # Public URL ile başlat
95
- interface.launch(share=True)
96
-
97
- """)
 
 
 
 
 
 
 
 
 
 
1
  with open("app.py", "w") as f:
2
  f.write("""
3
  import torch
 
36
  'mean_HR', 'symptom_duration', 'QTc_sinus', 'PVCCI_dispersion',
37
  'CI_variability', 'PVC_Peak_QRS_duration', 'PVCCI', 'PVC_Compansatory_interval']
38
 
39
+ # Mean değerleri ile varsayılanlar
40
+ numeric_means = {
41
+ 'pvc_percent': 11.96,
42
+ 'PVCQRS': 155.1,
43
+ 'EF': 59.93,
44
+ 'Age': 52.19,
45
+ 'PVC_Prematurity_index': 0.6158,
46
+ 'QRS_ratio': 1.933,
47
+ 'mean_HR': 71.28,
48
+ 'symptom_duration': 14.91,
49
+ 'QTc_sinus': 425.0,
50
+ 'PVCCI_dispersion': 57.1,
51
+ 'CI_variability': 22.98,
52
+ 'PVC_Peak_QRS_duration': 76.13,
53
+ 'PVCCI': 513.4,
54
+ 'PVC_Compansatory_interval': 1044
55
+ }
56
+
57
  # Model ve scaler'ı yükleme
58
+ model_path = "tabtransformer_model.pth"
59
+ scaler_path = "trans_scaler.pkl"
60
 
61
  # Model tanımı
62
  input_dim = len(categorical_features) + len(numeric_features) # Toplam giriş boyutu
 
90
  logits = model(tensor_data)
91
  probabilities = F.softmax(logits, dim=1).numpy()
92
 
93
+ return {
94
+ "Probability of Response": probabilities[0][0],
95
+ "Probability of Non-Response": probabilities[0][1]
96
+ }
97
 
98
  # Gradio arayüzü
99
  inputs = (
100
  [gr.Dropdown(choices=['Yes', 'No'], label=feature) for feature in categorical_features] +
101
+ [gr.Number(label=feature, value=numeric_means[feature]) for feature in numeric_features]
102
  )
103
  outputs = gr.Label(label="Prediction")
104
  interface = gr.Interface(fn=predict, inputs=inputs, outputs=outputs, title="TabTransformer Prediction")
105
 
106
+ # Spaces için başlatma
107
+ if __name__ == "__main__":
108
+ interface.launch(server_name="0.0.0.0", server_port=8080)""")